Permalink
Browse files

Allow one-off use of .meta({cascade}) and .meta({fetch}) to override …

…the relevant model settings on a case-by-case basis.
  • Loading branch information...
mikermcneil committed Oct 15, 2018
1 parent b3f18a6 commit 90d7113a383fba4bbc77ac4dd2e072634cba2681
Showing with 39 additions and 29 deletions.
  1. +39 −29 lib/waterline/utils/query/forge-stage-two-query.js
@@ -266,12 +266,14 @@ module.exports = function forgeStageTwoQuery(query, orm) {
throw new Error('Consistency violation: If specified, expecting `cascadeOnDestroy` model setting to be `true` or `false`. But instead, got: '+util.inspect(WLModel.cascadeOnDestroy, {depth:5})+'');
}
// Only bother setting the `cascade` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.cascadeOnDestroy) {
query.meta = query.meta || {};
query.meta.cascade = WLModel.cascadeOnDestroy;
}
if (!query.meta || query.meta.cascade === undefined) {
// Only bother setting the `cascade` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.cascadeOnDestroy) {
query.meta = query.meta || {};
query.meta.cascade = WLModel.cascadeOnDestroy;
}
}//
}//>-
@@ -284,12 +286,14 @@ module.exports = function forgeStageTwoQuery(query, orm) {
throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnUpdate` model setting to be `true` or `false`. But instead, got: '+util.inspect(WLModel.fetchRecordsOnUpdate, {depth:5})+'');
}
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnUpdate) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnUpdate;
}
if (!query.meta || query.meta.fetch === undefined) {
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnUpdate) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnUpdate;
}
}//
}//>-
@@ -301,12 +305,14 @@ module.exports = function forgeStageTwoQuery(query, orm) {
throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnDestroy` model setting to be `true` or `false`. But instead, got: '+util.inspect(WLModel.fetchRecordsOnDestroy, {depth:5})+'');
}
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnDestroy) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnDestroy;
}
if (!query.meta || query.meta.fetch === undefined) {
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnDestroy) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnDestroy;
}
}//
}//>-
@@ -318,12 +324,14 @@ module.exports = function forgeStageTwoQuery(query, orm) {
throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnCreate` model setting to be `true` or `false`. But instead, got: '+util.inspect(WLModel.fetchRecordsOnCreate, {depth:5})+'');
}
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnCreate) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnCreate;
}
if (!query.meta || query.meta.fetch === undefined) {
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnCreate) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnCreate;
}
}//
}//>-
@@ -335,11 +343,13 @@ module.exports = function forgeStageTwoQuery(query, orm) {
throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnCreateEach` model setting to be `true` or `false`. But instead, got: '+util.inspect(WLModel.fetchRecordsOnCreateEach, {depth:5})+'');
}
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnCreateEach) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnCreateEach;
if (!query.meta || query.meta.fetch === undefined) {
// Only bother setting the `fetch` meta key if the model setting is `true`.
// (because otherwise it's `false`, which is the default anyway)
if (WLModel.fetchRecordsOnCreateEach) {
query.meta = query.meta || {};
query.meta.fetch = WLModel.fetchRecordsOnCreateEach;
}
}
}//>-

0 comments on commit 90d7113

Please sign in to comment.