when using cradle if we don't wait for the schema to be connected, the models fails to load correctly.
This commit is contained in:
parent
75c96bdaa9
commit
fa50e0e5e8
|
@ -28,27 +28,31 @@ if (existsSync(confFile)) {
|
||||||
|
|
||||||
var schema = new Schema(config && config.driver || 'memory', config);
|
var schema = new Schema(config && config.driver || 'memory', config);
|
||||||
schema.log = log;
|
schema.log = log;
|
||||||
railway.orm._schemas.push(schema);
|
|
||||||
|
|
||||||
context = prepareContext(schema);
|
// when using cradle if we dont wait for the schema to be connected, the models fails to load correctly.
|
||||||
|
schema.on('connected', function() {
|
||||||
|
railway.orm._schemas.push(schema);
|
||||||
|
|
||||||
|
context = prepareContext(schema);
|
||||||
|
|
||||||
// run schema first
|
// run schema first
|
||||||
var schemaFile = (root || app.root) + '/db/schema.';
|
var schemaFile = (root || app.root) + '/db/schema.';
|
||||||
if (existsSync(schemaFile + 'js')) {
|
if (existsSync(schemaFile + 'js')) {
|
||||||
schemaFile += 'js';
|
schemaFile += 'js';
|
||||||
} else if (existsSync(schemaFile + 'coffee')) {
|
} else if (existsSync(schemaFile + 'coffee')) {
|
||||||
schemaFile += 'coffee';
|
schemaFile += 'coffee';
|
||||||
} else {
|
} else {
|
||||||
schemaFile = false;
|
schemaFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schemaFile) {
|
if (schemaFile) {
|
||||||
railway.utils.runCode(schemaFile, context);
|
railway.utils.runCode(schemaFile, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// and freeze schemas
|
// and freeze schemas
|
||||||
railway.orm._schemas.forEach(function (schema) {
|
railway.orm._schemas.forEach(function (schema) {
|
||||||
schema.freeze();
|
schema.freeze();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// check validations and display warning
|
// check validations and display warning
|
||||||
|
|
Loading…
Reference in New Issue