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

Multi ORM support #11

Open
wants to merge 2 commits into
base: for-sails-0.12
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
12 changes: 12 additions & 0 deletions lib/build-waterline-ontology.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ module.exports = function buildWaterlineOntology(hook, sails, cb) {
// First, instantiate a fresh, empty Waterline ORM instance.
var freshOntology = new Waterline();

//orm by default is Waterline
let defaultOrm = sails.config.models.defaultOrm || 'Waterline';
// Next, iterate through each normalized model definition and register it with Waterline
// (using the `loadCollection()` method).
_.each(hook.models, function _loadEachModelDefIntoWaterline(normalizedModelDef, identity) {
//check orm of model definition
if (normalizedModelDef.sequelize) {
normalizedModelDef.orm = 'Sequelize';
} else {
normalizedModelDef.orm = normalizedModelDef.orm || defaultOrm;
}
if (normalizedModelDef.orm != 'Waterline') {
sails.log.silly('Model `%s` registered in %s (ORM)', identity, normalizedModelDef.orm);
return;
}
// Create a Waterline "Collection" instance for each model, then register it w/ the ORM.
sails.log.silly('Registering model `%s` in Waterline (ORM)', identity);
freshOntology.loadCollection(Waterline.Collection.extend(normalizedModelDef));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-hook-orm",
"version": "1.0.10-1",
"version": "1.0.10-2",
"description": "The ORM hook from Sails core.",
"main": "index.js",
"scripts": {
Expand Down