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

Restore default ability to globally set defaults for all models #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Also you can set some parameters in `config/sequelize.js` to override defaults.
```
module.exports.sequelize = {
"clsNamespace": "myAppCLSNamespace",
"exposeToGlobal": true
"exposeToGlobal": true,
"modelDefaults": false //If set to an Object, allows to set default options for all models (Can be overriden in the model itself).
};
```

Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = sails => {
defaults: {
__configKey__: {
clsNamespace: 'sails-sequelize',
exposeToGlobal: true
exposeToGlobal: true,
modelDefaults: false
}
},
configure () {
Expand Down Expand Up @@ -82,6 +83,12 @@ module.exports = sails => {
return next(err);
}

if(sails.config[this.configKey].modelDefaults) {
Object.values(models).forEach((model) => {
model = _.defaultsDeep(model, sails.config[this.configKey].modelDefaults);
});
}

self.defineModels(models, connections);
self.migrateSchema(next, connections, models);
});
Expand Down