Merge branch 'release/2.3.1' into production
This commit is contained in:
commit
a848628db8
|
@ -1235,8 +1235,12 @@ var defineScope = require('./scope.js').defineScope;
|
|||
* @param {ModelClass} [targetClass] The model class for the query, default to
|
||||
* the declaring model
|
||||
*/
|
||||
DataAccessObject.scope = function (name, query, targetClass) {
|
||||
defineScope(this, targetClass || this, name, query);
|
||||
DataAccessObject.scope = function (name, query, targetClass, methods, options) {
|
||||
var cls = this;
|
||||
if (options && options.isStatic === false) {
|
||||
cls = cls.prototype;
|
||||
}
|
||||
defineScope(cls, targetClass || cls, name, query, methods, options);
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -378,7 +378,7 @@ function isModelDataSourceAttached(model) {
|
|||
DataSource.prototype.defineScopes = function (modelClass, scopes) {
|
||||
if(scopes) {
|
||||
for(var s in scopes) {
|
||||
defineScope(modelClass, modelClass, s, scopes[s]);
|
||||
defineScope(modelClass, modelClass, s, scopes[s], {}, scopes[s].options);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
14
lib/scope.js
14
lib/scope.js
|
@ -8,8 +8,9 @@ exports.defineScope = defineScope;
|
|||
exports.mergeQuery = mergeQuery;
|
||||
|
||||
function ScopeDefinition(definition) {
|
||||
this.modelFrom = definition.modelFrom || definition.sourceModel;
|
||||
this.modelTo = definition.modelTo || definition.targetModel;
|
||||
this.isStatic = definition.isStatic;
|
||||
this.modelFrom = definition.modelFrom;
|
||||
this.modelTo = definition.modelTo || definition.modelFrom;
|
||||
this.name = definition.name;
|
||||
this.params = definition.params;
|
||||
this.methods = definition.methods;
|
||||
|
@ -80,7 +81,11 @@ function defineScope(cls, targetClass, name, params, methods, options) {
|
|||
}
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
// Check if the cls is the class itself or its prototype
|
||||
var isStatic = (typeof cls === 'function') || options.isStatic || false;
|
||||
var definition = new ScopeDefinition({
|
||||
isStatic: isStatic,
|
||||
modelFrom: cls,
|
||||
modelTo: targetClass,
|
||||
name: name,
|
||||
|
@ -89,8 +94,13 @@ function defineScope(cls, targetClass, name, params, methods, options) {
|
|||
options: options || {}
|
||||
});
|
||||
|
||||
if(isStatic) {
|
||||
cls.scopes = cls.scopes || {};
|
||||
cls.scopes[name] = definition;
|
||||
} else {
|
||||
cls.constructor.scopes = cls.constructor.scopes || {};
|
||||
cls.constructor.scopes[name] = definition;
|
||||
}
|
||||
|
||||
// Define a property for the scope
|
||||
Object.defineProperty(cls, name, {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "loopback-datasource-juggler",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"description": "LoopBack DataSoure Juggler",
|
||||
"keywords": [
|
||||
"StrongLoop",
|
||||
|
|
Loading…
Reference in New Issue