Enhance support for composite keys
This commit is contained in:
parent
d9998d8294
commit
8912defe8e
|
@ -443,7 +443,7 @@ DataSource.prototype.discoverSchema = function (owner, table, cb) {
|
||||||
pks[pk.columnName] = pk.keySeq;
|
pks[pk.columnName] = pk.keySeq;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(pks);
|
// console.log(pks);
|
||||||
|
|
||||||
var foreignKeys = results[2];
|
var foreignKeys = results[2];
|
||||||
foreignKeys.forEach(function(fk) {
|
foreignKeys.forEach(function(fk) {
|
||||||
|
@ -455,7 +455,7 @@ DataSource.prototype.discoverSchema = function (owner, table, cb) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(fks);
|
// console.log(fks);
|
||||||
|
|
||||||
if (!columns) {
|
if (!columns) {
|
||||||
cb && cb();
|
cb && cb();
|
||||||
|
@ -492,6 +492,7 @@ DataSource.prototype.discoverSchema = function (owner, table, cb) {
|
||||||
schema.properties[propName][dataSourceName] = {
|
schema.properties[propName][dataSourceName] = {
|
||||||
columnName: i.columnName,
|
columnName: i.columnName,
|
||||||
dataType: i.dataType,
|
dataType: i.dataType,
|
||||||
|
dataLength: i.dataLength,
|
||||||
nullable: i.nullable
|
nullable: i.nullable
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -609,9 +610,9 @@ DataSource.prototype.idColumnName = function(modelName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the ID column name
|
* Find the ID property name
|
||||||
* @param modelName
|
* @param modelName
|
||||||
* @returns {String} columnName for ID
|
* @returns {String} property for ID
|
||||||
*/
|
*/
|
||||||
DataSource.prototype.idName = function(modelName) {
|
DataSource.prototype.idName = function(modelName) {
|
||||||
var props = this.definitions[modelName].properties;
|
var props = this.definitions[modelName].properties;
|
||||||
|
@ -623,6 +624,28 @@ DataSource.prototype.idName = function(modelName) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the ID property names sorted by the index
|
||||||
|
* @param modelName
|
||||||
|
* @returns {[String]} property names for IDs
|
||||||
|
*/
|
||||||
|
DataSource.prototype.idNames = function (modelName) {
|
||||||
|
var ids = [];
|
||||||
|
var props = this.definitions[modelName].properties;
|
||||||
|
for (var key in props) {
|
||||||
|
if (props[key].id && props[key].id > 0) {
|
||||||
|
ids.push({name: key, id: props[key].id});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ids.sort(function (a, b) {
|
||||||
|
return a.key - b.key;
|
||||||
|
});
|
||||||
|
var names = ids.map(function (id) {
|
||||||
|
return id.name;
|
||||||
|
});
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define foreign key
|
* Define foreign key
|
||||||
|
|
|
@ -98,6 +98,15 @@ BaseSQL.prototype.idName = function (model) {
|
||||||
return this.dataSource(model).idName(model);
|
return this.dataSource(model).idName(model);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the id property names
|
||||||
|
* @param model The model name
|
||||||
|
* @returns {[String]} The id property names
|
||||||
|
*/
|
||||||
|
BaseSQL.prototype.idNames = function (model) {
|
||||||
|
return this.dataSource(model).idNames(model);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the id column name
|
* Get the id column name
|
||||||
* @param model The model name
|
* @param model The model name
|
||||||
|
|
Loading…
Reference in New Issue