From 9a124d36c19e683b59e7ae2d2d1cd5d939a706d5 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Thu, 11 Jul 2013 00:02:29 -0500 Subject: [PATCH] allow a model to set a schema flag to true/false on adapters that allow it --- lib/hooks/orm/index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/hooks/orm/index.js b/lib/hooks/orm/index.js index ff716e3565..a00282ae4e 100644 --- a/lib/hooks/orm/index.js +++ b/lib/hooks/orm/index.js @@ -107,12 +107,26 @@ module.exports = function(sails) { function loadCollection(model, cb) { - // Wrap model in Waterline.Collection.extend - var Model = Waterline.Collection.extend(sails.models[model]); + // Determine if model is schema or schemaless + var modelAdapters = sails.models[model].adapter; + + // Check if main model adapter config has a default schema setting + var defaultSchema = sails.adapters[modelAdapters[0]].config.hasOwnProperty('schema'); + + // Check if the model is overriding the schema setting + var overrideSchema = typeof sails.models[model].schema !== 'undefined'; + + // Set the schema value if there is a default and nothing is overriding it + if(defaultSchema && !overrideSchema) { + sails.models[model].schema = sails.adapters[modelAdapters[0]].config.schema; + } // Mixin local model defaults to the adapters passed into the model var adapters = util.overrideConfig(model); + // Wrap model in Waterline.Collection.extend + var Model = Waterline.Collection.extend(sails.models[model]); + new Model({ // Pass in a default tableName, can be overwritten in a model definition