Fix the mapping
This commit is contained in:
parent
e51bd2d360
commit
2c2768e929
|
@ -132,6 +132,9 @@ Schema.prototype.define = function defineClass(className, properties, settings)
|
|||
};
|
||||
|
||||
var idInjection = settings.idInjection;
|
||||
if(idInjection !== false) {
|
||||
idInjection = true;
|
||||
}
|
||||
for(var p in properties) {
|
||||
if(properties[p].id) {
|
||||
idInjection = false;
|
||||
|
@ -142,15 +145,15 @@ Schema.prototype.define = function defineClass(className, properties, settings)
|
|||
}
|
||||
}
|
||||
// Add the id property
|
||||
if (idInjection !== false) {
|
||||
if (idInjection) {
|
||||
ModelClass.prototype.__defineGetter__('id', function () {
|
||||
return this.__data.id;
|
||||
});
|
||||
|
||||
// Set up the id property
|
||||
properties.id = properties.id || { type: Number, id: true };
|
||||
properties.id = properties.id || { type: Number, id: 1 };
|
||||
if (!properties.id.id) {
|
||||
properties.id.id = true;
|
||||
properties.id.id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -549,12 +549,11 @@ DataSource.prototype.idColumnName = function(modelName) {
|
|||
*/
|
||||
DataSource.prototype.idName = function(modelName) {
|
||||
var props = this.definitions[modelName].properties;
|
||||
var self = this;
|
||||
Object.keys(props).forEach(function(key) {
|
||||
for(var key in props) {
|
||||
if(props[key].id) {
|
||||
return key;
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
17
lib/sql.js
17
lib/sql.js
|
@ -22,18 +22,25 @@ BaseSQL.prototype.queryOne = function (sql, callback) {
|
|||
};
|
||||
|
||||
BaseSQL.prototype.dataSource = function(model) {
|
||||
if(!model) {
|
||||
console.log(new Error('model').stack);
|
||||
}
|
||||
return this._models[model].model.schema;
|
||||
}
|
||||
|
||||
BaseSQL.prototype.table = function (model) {
|
||||
return this.dataSource(model).tableName(model);
|
||||
var name = this.dataSource(model).tableName(model);
|
||||
var dbName = this.dbName;
|
||||
if(typeof dbName === 'function') {
|
||||
name = dbName(name);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.column = function (model, property) {
|
||||
return this.dataSource(model).columnName(model, property);
|
||||
var name = this.dataSource(model).columnName(model, property);
|
||||
var dbName = this.dbName;
|
||||
if(typeof dbName === 'function') {
|
||||
name = dbName(name);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.idName = function (model) {
|
||||
|
|
Loading…
Reference in New Issue