Skip to content

Commit e693c16

Browse files
committed
Trying to setup sequelize and waterline models together
1 parent fb46abb commit e693c16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+16123
-25
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ build/Release
2525
# Dependency directory
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
28-
29-
test/sails_versions

index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ module.exports = sails => {
6868
for (connectionName in datastores) {
6969
connection = datastores[connectionName];
7070

71+
// Skip waterline connections
72+
if (connection.adapter) {
73+
continue;
74+
}
75+
7176
if (!connection.options) {
7277
connection.options = {};
7378
}
@@ -107,10 +112,14 @@ module.exports = sails => {
107112

108113
for (modelName in models) {
109114
modelDef = models[modelName];
110-
sails.log.verbose('Loading model \'' + modelDef.globalId + '\'');
111115

112-
connectionName = modelDef.options.connection || modelDef.datastore || defaultConnection;
116+
// Skip models without options provided (possible Waterline models)
117+
if (!modelDef.options) {
118+
continue;
119+
}
113120

121+
sails.log.verbose('Loading model \'' + modelDef.globalId + '\'');
122+
connectionName = modelDef.connection || modelDef.datastore || defaultConnection;
114123
modelClass = connections[connectionName].define(modelDef.globalId, modelDef.attributes, modelDef.options);
115124

116125
if (sequelizeMajVersion >= 4) {
@@ -132,6 +141,12 @@ module.exports = sails => {
132141

133142
for (modelName in models) {
134143
modelDef = models[modelName];
144+
145+
// Skip models without options provided (possible Waterline models)
146+
if (!modelDef.options) {
147+
continue;
148+
}
149+
135150
this.setAssociation(modelDef);
136151
this.setDefaultScope(modelDef, sails.models[modelDef.globalId.toLowerCase()]);
137152
}
@@ -176,6 +191,11 @@ module.exports = sails => {
176191
for (connectionName in datastores) {
177192
connectionDescription = datastores[connectionName];
178193

194+
// Skip waterline connections
195+
if (connectionDescription.adapter) {
196+
continue;
197+
}
198+
179199
sails.log.verbose('Migrating schema in \'' + connectionName + '\' connection');
180200

181201
if (connectionDescription.dialect === 'postgres') {
@@ -199,9 +219,10 @@ module.exports = sails => {
199219
} else {
200220
syncTasks.push(connections[connectionName].sync({ force: forceSync }));
201221
}
202-
203-
Promise.all(syncTasks).then(() => next()).catch(e => next(e));
204222
}
223+
224+
Promise.all(syncTasks).then(() => next()).catch(e => next(e));
225+
205226
}
206227
}
207228
};

0 commit comments

Comments
 (0)