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
|
* @param {ModelClass} [targetClass] The model class for the query, default to
|
||||||
* the declaring model
|
* the declaring model
|
||||||
*/
|
*/
|
||||||
DataAccessObject.scope = function (name, query, targetClass) {
|
DataAccessObject.scope = function (name, query, targetClass, methods, options) {
|
||||||
defineScope(this, targetClass || this, name, query);
|
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) {
|
DataSource.prototype.defineScopes = function (modelClass, scopes) {
|
||||||
if(scopes) {
|
if(scopes) {
|
||||||
for(var s in 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;
|
exports.mergeQuery = mergeQuery;
|
||||||
|
|
||||||
function ScopeDefinition(definition) {
|
function ScopeDefinition(definition) {
|
||||||
this.modelFrom = definition.modelFrom || definition.sourceModel;
|
this.isStatic = definition.isStatic;
|
||||||
this.modelTo = definition.modelTo || definition.targetModel;
|
this.modelFrom = definition.modelFrom;
|
||||||
|
this.modelTo = definition.modelTo || definition.modelFrom;
|
||||||
this.name = definition.name;
|
this.name = definition.name;
|
||||||
this.params = definition.params;
|
this.params = definition.params;
|
||||||
this.methods = definition.methods;
|
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({
|
var definition = new ScopeDefinition({
|
||||||
|
isStatic: isStatic,
|
||||||
modelFrom: cls,
|
modelFrom: cls,
|
||||||
modelTo: targetClass,
|
modelTo: targetClass,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -89,8 +94,13 @@ function defineScope(cls, targetClass, name, params, methods, options) {
|
||||||
options: options || {}
|
options: options || {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(isStatic) {
|
||||||
cls.scopes = cls.scopes || {};
|
cls.scopes = cls.scopes || {};
|
||||||
cls.scopes[name] = definition;
|
cls.scopes[name] = definition;
|
||||||
|
} else {
|
||||||
|
cls.constructor.scopes = cls.constructor.scopes || {};
|
||||||
|
cls.constructor.scopes[name] = definition;
|
||||||
|
}
|
||||||
|
|
||||||
// Define a property for the scope
|
// Define a property for the scope
|
||||||
Object.defineProperty(cls, name, {
|
Object.defineProperty(cls, name, {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "loopback-datasource-juggler",
|
"name": "loopback-datasource-juggler",
|
||||||
"version": "2.3.0",
|
"version": "2.3.1",
|
||||||
"description": "LoopBack DataSoure Juggler",
|
"description": "LoopBack DataSoure Juggler",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"StrongLoop",
|
"StrongLoop",
|
||||||
|
|
Loading…
Reference in New Issue