Fix the mapping

This commit is contained in:
Raymond Feng 2013-05-23 10:46:01 -07:00
parent e51bd2d360
commit 2c2768e929
3 changed files with 20 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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) {