Fix belongsTo relation
This commit is contained in:
parent
8360576c40
commit
e5824356ca
|
@ -232,7 +232,7 @@ DataSource.prototype.setup = function(name, settings) {
|
|||
}
|
||||
connector = require(name);
|
||||
} catch (e) {
|
||||
return console.log('\nWARNING: LoopbackData connector "' + name + '" is not installed,\nso your models would not work, to fix run:\n\n npm install ' + name, '\n');
|
||||
return console.log('\nWARNING: LoopBack connector "' + name + '" is not installed,\nso your models would not work, to fix run:\n\n npm install ' + name, '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -920,7 +920,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
|
|||
}
|
||||
|
||||
var self = this;
|
||||
var schemaName = this.name || this.connector.name;
|
||||
var schemaName = this.connector.name || this.name;
|
||||
|
||||
var tasks = [
|
||||
this.discoverModelProperties.bind(this, modelName, options),
|
||||
|
@ -1027,14 +1027,13 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) {
|
|||
console.log('Foreign keys: ', fks);
|
||||
}
|
||||
|
||||
schema.options.relations = {};
|
||||
foreignKeys.forEach(function (fk) {
|
||||
var propName = fromDBName(fk.pkTableName, true);
|
||||
schema.properties[propName] = {
|
||||
type: fromDBName(fk.pkTableName, false),
|
||||
relation: {
|
||||
type: 'belongsTo',
|
||||
foreignKey: fromDBName(fk.pkColumnName, true)
|
||||
}
|
||||
schema.options.relations[propName] = {
|
||||
model: fromDBName(fk.pkTableName, false),
|
||||
type: 'belongsTo',
|
||||
foreignKey: fromDBName(fk.fkColumnName, true)
|
||||
};
|
||||
|
||||
var key = fk.pkOwner + '.' + fk.pkTableName;
|
||||
|
@ -1175,14 +1174,13 @@ DataSource.prototype.discoverSchemasSync = function (modelName, options) {
|
|||
console.log('Foreign keys: ', fks);
|
||||
}
|
||||
|
||||
schema.options.relations = {};
|
||||
foreignKeys.forEach(function (fk) {
|
||||
var propName = fromDBName(fk.pkTableName, true);
|
||||
schema.properties[propName] = {
|
||||
type: fromDBName(fk.pkTableName, false),
|
||||
relation: {
|
||||
type: 'belongsTo',
|
||||
foreignKey: fromDBName(fk.pkColumnName, true)
|
||||
}
|
||||
schema.options.relations[propName] = {
|
||||
model: fromDBName(fk.pkTableName, false),
|
||||
type: 'belongsTo',
|
||||
foreignKey: fromDBName(fk.fkColumnName, true)
|
||||
};
|
||||
|
||||
var key = fk.pkOwner + '.' + fk.pkTableName;
|
||||
|
|
|
@ -195,7 +195,7 @@ Relation.belongsTo = function (anotherClass, params) {
|
|||
}
|
||||
}
|
||||
|
||||
var idName = this.dataSource.idName(this.modelName) || 'id';
|
||||
var idName = this.dataSource.idName(anotherClass.modelName) || 'id';
|
||||
var methodName = params.as || i8n.camelize(anotherClass.modelName, true);
|
||||
var fk = params.foreignKey || methodName + 'Id';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "loopback-datasource-juggler",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"description": "LoopBack DataSoure Juggler",
|
||||
"keywords": [
|
||||
"StrongLoop",
|
||||
|
|
Loading…
Reference in New Issue