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,10 +94,14 @@ DataAccessObject.applyScope = function(query) {
};
DataAccessObject.applyProperties = function(data) {
var scope = this.defaultScope(data, true) || {};
if (typeof scope.where === 'object'
&& this.definition.settings.applyProperties !== false) {
setScopeValuesFromWhere(data, scope.where, this);
var properties = this.definition.settings.properties;
if (typeof properties === 'object') {
util._extend(data, properties);
} else if (properties !== false) {
var scope = this.defaultScope(data, true) || {};
if (typeof scope.where === 'object') {
setScopeValuesFromWhere(data, scope.where, this);
}
}
};

View File

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