This commit is contained in:
parent
d930972d3e
commit
a5f11ac5f5
26
lib/sql.js
26
lib/sql.js
|
@ -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;
|
||||
|
|
|
@ -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']});
|
||||
|
|
Loading…
Reference in New Issue