applyProperties => properties (object/false)

This commit is contained in:
Fabien Franzen 2014-09-07 14:12:14 +02:00
parent 702796a486
commit beeb7c46c9
2 changed files with 9 additions and 4 deletions

View File

@ -94,11 +94,15 @@ DataAccessObject.applyScope = function(query) {
}; };
DataAccessObject.applyProperties = function(data) { DataAccessObject.applyProperties = function(data) {
var properties = this.definition.settings.properties;
if (typeof properties === 'object') {
util._extend(data, properties);
} else if (properties !== false) {
var scope = this.defaultScope(data, true) || {}; var scope = this.defaultScope(data, true) || {};
if (typeof scope.where === 'object' if (typeof scope.where === 'object') {
&& this.definition.settings.applyProperties !== false) {
setScopeValuesFromWhere(data, scope.where, this); setScopeValuesFromWhere(data, scope.where, this);
} }
}
}; };
/** /**

View File

@ -74,6 +74,7 @@ describe('default scope', function () {
Widget = db.define('Widget', Product.definition.properties, { Widget = db.define('Widget', Product.definition.properties, {
base: 'Product', base: 'Product',
properties: { kind: 'Widget' },
scope: { where: { kind: 'Widget' }, order: 'name' }, scope: { where: { kind: 'Widget' }, order: 'name' },
scopes: { active: { where: { active: true } } }, scopes: { active: { where: { active: true } } },
mongodb: { collection: 'Product' }, mongodb: { collection: 'Product' },