Raymond Feng 2015-05-22 08:52:40 -07:00
parent d930972d3e
commit a5f11ac5f5
2 changed files with 17 additions and 12 deletions

View File

@ -860,21 +860,25 @@ SQLConnector.prototype.buildFields = function(model, data, excludeIds) {
for (var i = 0, n = keys.length; i < n; i++) {
var key = keys[i];
var p = props[key];
if (p == null) {
// Unknown property, ignore it
debug('Unknown property %s is skipped for model %s', key, model);
continue;
}
if (excludeIds && p.id) {
continue;
}
if (p) {
var k = this.columnEscaped(model, key);
var v = this.toColumnValue(p, data[key]);
if (v !== undefined) {
fields.names.push(k);
if (v instanceof ParameterizedSQL) {
fields.columnValues.push(v);
} else {
fields.columnValues.push(new ParameterizedSQL(PLACEHOLDER, [v]));
}
fields.properties.push(p);
var k = this.columnEscaped(model, key);
var v = this.toColumnValue(p, data[key]);
if (v !== undefined) {
fields.names.push(k);
if (v instanceof ParameterizedSQL) {
fields.columnValues.push(v);
} else {
fields.columnValues.push(new ParameterizedSQL(PLACEHOLDER, [v]));
}
fields.properties.push(p);
}
}
return fields;

View File

@ -143,7 +143,8 @@ describe('sql connector', function() {
});
it('builds fields for columns', function() {
var fields = connector.buildFields('customer', {name: 'John', vip: true});
var fields = connector.buildFields('customer',
{name: 'John', vip: true, unknown: 'Random'});
expect(fields.names).to.eql(['`NAME`', '`VIP`']);
expect(fields.columnValues[0].toJSON()).to.eql(
{sql: '?', params: ['John']});