Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema True/False flag #558

Merged
merged 1 commit into from
Jul 11, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/hooks/orm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down