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:
Muneeb Samuels 2012-11-10 20:14:13 +02:00
parent 75c96bdaa9
commit fa50e0e5e8
1 changed files with 19 additions and 15 deletions

View File

@ -28,27 +28,31 @@ if (existsSync(confFile)) {
var schema = new Schema(config && config.driver || 'memory', config);
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
var schemaFile = (root || app.root) + '/db/schema.';
if (existsSync(schemaFile + 'js')) {
schemaFile += 'js';
} else if (existsSync(schemaFile + 'coffee')) {
schemaFile += 'coffee';
} else {
schemaFile = false;
}
var schemaFile = (root || app.root) + '/db/schema.';
if (existsSync(schemaFile + 'js')) {
schemaFile += 'js';
} else if (existsSync(schemaFile + 'coffee')) {
schemaFile += 'coffee';
} else {
schemaFile = false;
}
if (schemaFile) {
railway.utils.runCode(schemaFile, context);
}
if (schemaFile) {
railway.utils.runCode(schemaFile, context);
}
// and freeze schemas
railway.orm._schemas.forEach(function (schema) {
schema.freeze();
railway.orm._schemas.forEach(function (schema) {
schema.freeze();
});
});
// check validations and display warning