Fix cradle+railwayjs
This commit is contained in:
commit
f929272fa3
|
@ -50,33 +50,36 @@ module.exports = function init(root) {
|
|||
|
||||
var schema = new Schema(config && config.driver || 'memory', config);
|
||||
schema.log = log;
|
||||
railway.orm._schemas.push(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);
|
||||
|
||||
var context = prepareContext(models, railway, app, schema);
|
||||
var context = prepareContext(models, railway, app, 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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (schemaFile) {
|
||||
var code = fs.readFileSync(schemaFile).toString();
|
||||
if (schemaFile.match(/\.coffee$/)) {
|
||||
code = require('coffee-script').compile(code);
|
||||
}
|
||||
var fn = new Function('context', 'require', 'with(context){(function(){' + code + '})()}');
|
||||
fn(context, require);
|
||||
}
|
||||
if (schemaFile) {
|
||||
var code = fs.readFileSync(schemaFile).toString();
|
||||
if (schemaFile.match(/\.coffee$/)) {
|
||||
code = require('coffee-script').compile(code);
|
||||
}
|
||||
var fn = new Function('context', 'require', 'with(context){(function(){' + code + '})()}');
|
||||
fn(context, require);
|
||||
}
|
||||
|
||||
// and freeze schemas
|
||||
railway.orm._schemas.forEach(function (schema) {
|
||||
schema.freeze();
|
||||
});
|
||||
// and freeze schemas
|
||||
railway.orm._schemas.forEach(function (schema) {
|
||||
schema.freeze();
|
||||
});
|
||||
});
|
||||
|
||||
// check validations and display warning
|
||||
|
||||
|
|
Loading…
Reference in New Issue