Fix railway 1.0 support
This commit is contained in:
parent
8cee0ec9b2
commit
f7aed3a814
|
@ -9,16 +9,17 @@ if (global.railway) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function init(root) {
|
module.exports = function init(root) {
|
||||||
var railway, app;
|
var railway, app, models;
|
||||||
|
|
||||||
if (typeof root !== 'object' || root.constructor.name !== 'Railway') {
|
if (typeof root !== 'object' || root.constructor.name !== 'Railway') {
|
||||||
railway = global.railway;
|
railway = global.railway;
|
||||||
app = global.app;
|
app = global.app;
|
||||||
railway.models = app.models;
|
models = app.models;
|
||||||
} else {
|
} else {
|
||||||
railway = root;
|
railway = root;
|
||||||
app = railway.app;
|
app = railway.app;
|
||||||
root = railway.root;
|
root = railway.root;
|
||||||
|
models = railway.models;
|
||||||
}
|
}
|
||||||
|
|
||||||
railway.orm._schemas = [];
|
railway.orm._schemas = [];
|
||||||
|
@ -80,8 +81,8 @@ railway.orm._schemas.forEach(function (schema) {
|
||||||
// check validations and display warning
|
// check validations and display warning
|
||||||
|
|
||||||
var displayWarning = false;
|
var displayWarning = false;
|
||||||
Object.keys(railway.models).forEach(function (model) {
|
Object.keys(models).forEach(function (model) {
|
||||||
var Model = railway.models[model];
|
var Model = models[model];
|
||||||
if (Model._validations) {
|
if (Model._validations) {
|
||||||
displayWarning = true;
|
displayWarning = true;
|
||||||
}
|
}
|
||||||
|
@ -163,15 +164,15 @@ function prepareContext(railway, app, defSchema, done) {
|
||||||
ctx.describe = ctx.define = function (className, callback) {
|
ctx.describe = ctx.define = function (className, callback) {
|
||||||
var m;
|
var m;
|
||||||
cname = className;
|
cname = className;
|
||||||
models[cname] = {};
|
_models[cname] = {};
|
||||||
settings[cname] = {};
|
settings[cname] = {};
|
||||||
if (nonJugglingSchema) {
|
if (nonJugglingSchema) {
|
||||||
m = callback;
|
m = callback;
|
||||||
} else {
|
} else {
|
||||||
callback && callback();
|
callback && callback();
|
||||||
m = (schema || defSchema).define(className, models[cname], settings[cname]);
|
m = (schema || defSchema).define(className, _models[cname], settings[cname]);
|
||||||
}
|
}
|
||||||
return railway.models[cname] = ctx[cname] = m;
|
return models[cname] = ctx[cname] = m;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,7 +185,7 @@ function prepareContext(railway, app, defSchema, done) {
|
||||||
type = String;
|
type = String;
|
||||||
}
|
}
|
||||||
params.type = type || String;
|
params.type = type || String;
|
||||||
models[cname][name] = params;
|
_models[cname][name] = params;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "jugglingdb",
|
"name": "jugglingdb",
|
||||||
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
|
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
|
||||||
"version": "0.1.24-pre2",
|
"version": "0.1.26",
|
||||||
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
|
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
||||||
|
|
Loading…
Reference in New Issue