@rvoh/dream 0.36.4 → 0.37.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/src/Dream.js +29 -23
- package/dist/cjs/src/decorators/field/association/HasMany.js +12 -12
- package/dist/cjs/src/decorators/field/association/HasOne.js +12 -12
- package/dist/cjs/src/decorators/field/association/shared.js +7 -7
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +31 -25
- package/dist/cjs/src/dream/Query.js +96 -88
- package/dist/cjs/src/dream/internal/associations/associationQuery.js +3 -3
- package/dist/cjs/src/dream/internal/associations/associationUpdateQuery.js +3 -3
- package/dist/cjs/src/dream/internal/associations/destroyAssociation.js +2 -2
- package/dist/cjs/src/dream/internal/associations/undestroyAssociation.js +2 -2
- package/dist/cjs/src/dream/internal/similarity/SimilarityBuilder.js +12 -12
- package/dist/cjs/src/errors/{CannotDefineAssociationWithBothDependentAndRequiredOnClause.js → CannotDefineAssociationWithBothDependentAndRequiredAndClause.js} +2 -2
- package/dist/cjs/src/errors/associations/{MissingRequiredAssociationOnClause.js → MissingRequiredAssociationAndClause.js} +4 -4
- package/dist/cjs/src/errors/associations/MissingRequiredPassthroughForAssociationAndClause.js +16 -0
- package/dist/cjs/src/helpers/cli/SchemaBuilder.js +1 -1
- package/dist/esm/src/Dream.js +29 -23
- package/dist/esm/src/decorators/field/association/HasMany.js +12 -12
- package/dist/esm/src/decorators/field/association/HasOne.js +12 -12
- package/dist/esm/src/decorators/field/association/shared.js +7 -7
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +31 -25
- package/dist/esm/src/dream/Query.js +96 -88
- package/dist/esm/src/dream/internal/associations/associationQuery.js +3 -3
- package/dist/esm/src/dream/internal/associations/associationUpdateQuery.js +3 -3
- package/dist/esm/src/dream/internal/associations/destroyAssociation.js +2 -2
- package/dist/esm/src/dream/internal/associations/undestroyAssociation.js +2 -2
- package/dist/esm/src/dream/internal/similarity/SimilarityBuilder.js +12 -12
- package/dist/esm/src/errors/{CannotDefineAssociationWithBothDependentAndRequiredOnClause.js → CannotDefineAssociationWithBothDependentAndRequiredAndClause.js} +1 -1
- package/dist/esm/src/errors/associations/{MissingRequiredAssociationOnClause.js → MissingRequiredAssociationAndClause.js} +3 -3
- package/dist/esm/src/errors/associations/MissingRequiredPassthroughForAssociationAndClause.js +13 -0
- package/dist/esm/src/helpers/cli/SchemaBuilder.js +1 -1
- package/dist/types/src/Dream.d.ts +11 -11
- package/dist/types/src/decorators/field/association/shared.d.ts +2 -2
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +11 -11
- package/dist/types/src/dream/Query.d.ts +15 -15
- package/dist/types/src/dream/internal/associations/associationQuery.d.ts +3 -3
- package/dist/types/src/dream/internal/associations/associationUpdateQuery.d.ts +3 -3
- package/dist/types/src/dream/internal/associations/destroyAssociation.d.ts +3 -3
- package/dist/types/src/dream/internal/associations/undestroyAssociation.d.ts +3 -3
- package/dist/types/src/dream/internal/similarity/SimilarityBuilder.d.ts +5 -5
- package/dist/types/src/errors/{CannotDefineAssociationWithBothDependentAndRequiredOnClause.d.ts → CannotDefineAssociationWithBothDependentAndRequiredAndClause.d.ts} +1 -1
- package/dist/types/src/errors/associations/{MissingRequiredAssociationOnClause.d.ts → MissingRequiredAssociationAndClause.d.ts} +1 -1
- package/dist/types/src/errors/associations/MissingRequiredPassthroughForAssociationAndClause.d.ts +5 -0
- package/dist/types/src/types/associations/shared.d.ts +16 -14
- package/dist/types/src/types/dream.d.ts +15 -15
- package/dist/types/src/types/variadic.d.ts +5 -5
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +126 -126
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializer.html +2 -2
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/Query.html +54 -54
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/Attribute.html +1 -1
- package/docs/functions/RendersMany.html +1 -1
- package/docs/functions/RendersOne.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/debug.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/index.html +1 -1
- package/docs/interfaces/AttributeStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
- package/docs/interfaces/DreamApplicationOpts.html +2 -2
- package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
- package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
- package/docs/types/SerializableDreamOrViewModel.html +1 -1
- package/docs/types/SerializableTypes.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModelSerializerKey.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +1 -1
- package/dist/cjs/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.js +0 -16
- package/dist/esm/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.js +0 -13
- package/dist/types/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.d.ts +0 -5
|
@@ -9,8 +9,8 @@ const AssociationDeclaredWithoutAssociatedDreamClass_js_1 = require("../errors/a
|
|
|
9
9
|
const CannotAssociateThroughPolymorphic_js_1 = require("../errors/associations/CannotAssociateThroughPolymorphic.js");
|
|
10
10
|
const CannotJoinPolymorphicBelongsToError_js_1 = require("../errors/associations/CannotJoinPolymorphicBelongsToError.js");
|
|
11
11
|
const JoinAttemptedOnMissingAssociation_js_1 = require("../errors/associations/JoinAttemptedOnMissingAssociation.js");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const MissingRequiredAssociationAndClause_js_1 = require("../errors/associations/MissingRequiredAssociationAndClause.js");
|
|
13
|
+
const MissingRequiredPassthroughForAssociationAndClause_js_1 = require("../errors/associations/MissingRequiredPassthroughForAssociationAndClause.js");
|
|
14
14
|
const MissingThroughAssociation_js_1 = require("../errors/associations/MissingThroughAssociation.js");
|
|
15
15
|
const MissingThroughAssociationSource_js_1 = require("../errors/associations/MissingThroughAssociationSource.js");
|
|
16
16
|
const CannotCallUndestroyOnANonSoftDeleteModel_js_1 = require("../errors/CannotCallUndestroyOnANonSoftDeleteModel.js");
|
|
@@ -152,7 +152,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
152
152
|
* stores the joins on statements applied to the
|
|
153
153
|
* current Query instance
|
|
154
154
|
*/
|
|
155
|
-
|
|
155
|
+
innerJoinAndStatements = Object.freeze({});
|
|
156
156
|
/**
|
|
157
157
|
* @internal
|
|
158
158
|
*
|
|
@@ -166,7 +166,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
166
166
|
* stores the joins on statements applied to the
|
|
167
167
|
* current Query instance
|
|
168
168
|
*/
|
|
169
|
-
|
|
169
|
+
leftJoinAndStatements = Object.freeze({});
|
|
170
170
|
/**
|
|
171
171
|
* @internal
|
|
172
172
|
*
|
|
@@ -236,9 +236,9 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
236
236
|
this.preloadStatements = Object.freeze(opts.preloadStatements || {});
|
|
237
237
|
this.preloadOnStatements = Object.freeze(opts.preloadOnStatements || {});
|
|
238
238
|
this.innerJoinStatements = Object.freeze(opts.innerJoinStatements || {});
|
|
239
|
-
this.
|
|
239
|
+
this.innerJoinAndStatements = Object.freeze(opts.innerJoinAndStatements || {});
|
|
240
240
|
this.leftJoinStatements = Object.freeze(opts.leftJoinStatements || {});
|
|
241
|
-
this.
|
|
241
|
+
this.leftJoinAndStatements = Object.freeze(opts.leftJoinAndStatements || {});
|
|
242
242
|
this.baseSqlAlias = opts.baseSqlAlias || this.tableName;
|
|
243
243
|
this.baseSelectQuery = opts.baseSelectQuery || null;
|
|
244
244
|
this.limitStatement = opts.limit || null;
|
|
@@ -310,16 +310,16 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
310
310
|
order: opts.order === null ? [] : [...this.orderStatements, ...(opts.order || [])],
|
|
311
311
|
distinctColumn: opts.distinctColumn !== undefined ? opts.distinctColumn : this.distinctColumn,
|
|
312
312
|
loadFromJoins: opts.loadFromJoins !== undefined ? opts.loadFromJoins : this.joinLoadActivated,
|
|
313
|
-
// when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and
|
|
313
|
+
// when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and innerJoinAndStatements are already
|
|
314
314
|
// cloned versions of the `this.` versions, handled in the `preload` and `joins` methods
|
|
315
315
|
preloadStatements: opts.preloadStatements || this.preloadStatements,
|
|
316
316
|
preloadOnStatements: opts.preloadOnStatements || this.preloadOnStatements,
|
|
317
317
|
innerJoinDreamClasses: opts.innerJoinDreamClasses || this.innerJoinDreamClasses,
|
|
318
318
|
innerJoinStatements: opts.innerJoinStatements || this.innerJoinStatements,
|
|
319
|
-
|
|
319
|
+
innerJoinAndStatements: opts.innerJoinAndStatements || this.innerJoinAndStatements,
|
|
320
320
|
leftJoinStatements: opts.leftJoinStatements || this.leftJoinStatements,
|
|
321
|
-
|
|
322
|
-
// end:when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and
|
|
321
|
+
leftJoinAndStatements: opts.leftJoinAndStatements || this.leftJoinAndStatements,
|
|
322
|
+
// end:when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and innerJoinAndStatements are already...
|
|
323
323
|
bypassAllDefaultScopes: opts.bypassAllDefaultScopes !== undefined ? opts.bypassAllDefaultScopes : this.bypassAllDefaultScopes,
|
|
324
324
|
bypassAllDefaultScopesExceptOnAssociations: opts.bypassAllDefaultScopesExceptOnAssociations !== undefined
|
|
325
325
|
? opts.bypassAllDefaultScopesExceptOnAssociations
|
|
@@ -465,7 +465,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
465
465
|
* // [Reply{id: 1}, Reply{id: 2}]
|
|
466
466
|
* ```
|
|
467
467
|
*
|
|
468
|
-
* @param args - A chain of association names and
|
|
468
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
469
469
|
* @returns A cloned Query with the joinLoad statement applied
|
|
470
470
|
*/
|
|
471
471
|
leftJoinPreload(...args) {
|
|
@@ -487,7 +487,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
487
487
|
* // [Reply{id: 1}, Reply{id: 2}]
|
|
488
488
|
* ```
|
|
489
489
|
*
|
|
490
|
-
* @param args - A chain of association names and
|
|
490
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
491
491
|
* @returns A cloned Query with the preload statement applied
|
|
492
492
|
*/
|
|
493
493
|
preload(...args) {
|
|
@@ -504,36 +504,44 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
504
504
|
* await User.query().innerJoin('posts').first()
|
|
505
505
|
* ```
|
|
506
506
|
*
|
|
507
|
-
* @param args - A chain of association names and
|
|
507
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
508
508
|
* @returns A cloned Query with the joins clause applied
|
|
509
509
|
*/
|
|
510
510
|
innerJoin(...args) {
|
|
511
511
|
const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
|
|
512
512
|
const innerJoinStatements = (0, cloneDeepSafe_js_1.default)(this.innerJoinStatements);
|
|
513
|
-
const
|
|
514
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, innerJoinStatements,
|
|
515
|
-
return this.clone({
|
|
513
|
+
const innerJoinAndStatements = (0, cloneDeepSafe_js_1.default)(this.innerJoinAndStatements);
|
|
514
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, innerJoinStatements, innerJoinAndStatements, null, [...args]);
|
|
515
|
+
return this.clone({
|
|
516
|
+
innerJoinDreamClasses,
|
|
517
|
+
innerJoinStatements,
|
|
518
|
+
innerJoinAndStatements,
|
|
519
|
+
});
|
|
516
520
|
}
|
|
517
521
|
/**
|
|
518
522
|
* @internal
|
|
519
523
|
*
|
|
520
|
-
* @param args - A chain of association names and
|
|
524
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
521
525
|
* @returns A cloned Query with the joins clause applied
|
|
522
526
|
*/
|
|
523
527
|
leftJoin(...args) {
|
|
524
528
|
const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
|
|
525
529
|
const leftJoinStatements = (0, cloneDeepSafe_js_1.default)(this.leftJoinStatements);
|
|
526
|
-
const
|
|
527
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, leftJoinStatements,
|
|
530
|
+
const leftJoinAndStatements = (0, cloneDeepSafe_js_1.default)(this.leftJoinAndStatements);
|
|
531
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, leftJoinStatements, leftJoinAndStatements, null, [
|
|
528
532
|
...args,
|
|
529
533
|
]);
|
|
530
|
-
return this.clone({
|
|
534
|
+
return this.clone({
|
|
535
|
+
innerJoinDreamClasses,
|
|
536
|
+
leftJoinStatements,
|
|
537
|
+
leftJoinAndStatements,
|
|
538
|
+
});
|
|
531
539
|
}
|
|
532
540
|
/**
|
|
533
541
|
* @internal
|
|
534
542
|
*
|
|
535
543
|
*/
|
|
536
|
-
fleshOutJoinStatements(innerJoinDreamClasses, joinStatements,
|
|
544
|
+
fleshOutJoinStatements(innerJoinDreamClasses, joinStatements, joinAndStatements, previousAssociationName, associationStatements, previousDreamClass = this.dreamClass) {
|
|
537
545
|
const nextAssociationStatement = associationStatements.shift();
|
|
538
546
|
if (nextAssociationStatement === undefined) {
|
|
539
547
|
// just satisfying typing
|
|
@@ -542,11 +550,11 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
542
550
|
const nextStatement = nextAssociationStatement;
|
|
543
551
|
if (!joinStatements[nextStatement])
|
|
544
552
|
joinStatements[(0, protectAgainstPollutingAssignment_js_1.default)(nextStatement)] = {};
|
|
545
|
-
if (!
|
|
546
|
-
|
|
553
|
+
if (!joinAndStatements[nextStatement])
|
|
554
|
+
joinAndStatements[(0, protectAgainstPollutingAssignment_js_1.default)(nextStatement)] = {};
|
|
547
555
|
const nextDreamClass = this.addAssociatedDreamClassToInnerJoinDreamClasses(previousDreamClass, nextStatement, innerJoinDreamClasses);
|
|
548
556
|
const nextJoinsStatements = joinStatements[nextStatement];
|
|
549
|
-
const nextJoinsOnStatements =
|
|
557
|
+
const nextJoinsOnStatements = joinAndStatements[nextStatement];
|
|
550
558
|
this.fleshOutJoinStatements(innerJoinDreamClasses, nextJoinsStatements, nextJoinsOnStatements, nextStatement, associationStatements, nextDreamClass);
|
|
551
559
|
//
|
|
552
560
|
}
|
|
@@ -564,9 +572,9 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
564
572
|
const clonedNextAssociationStatement = (0, cloneDeepSafe_js_1.default)(nextAssociationStatement);
|
|
565
573
|
const keys = Object.keys(clonedNextAssociationStatement);
|
|
566
574
|
keys.forEach((key) => {
|
|
567
|
-
|
|
575
|
+
joinAndStatements[(0, protectAgainstPollutingAssignment_js_1.default)(key)] = clonedNextAssociationStatement[key];
|
|
568
576
|
});
|
|
569
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, joinStatements,
|
|
577
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, joinStatements, joinAndStatements, previousAssociationName, associationStatements, previousDreamClass);
|
|
570
578
|
}
|
|
571
579
|
}
|
|
572
580
|
/**
|
|
@@ -786,7 +794,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
786
794
|
* public localizedTexts: LocalizedText[]
|
|
787
795
|
*
|
|
788
796
|
* @deco.HasOne('LocalizedText', {
|
|
789
|
-
*
|
|
797
|
+
* and: { locale: DreamConst.passthrough },
|
|
790
798
|
* })
|
|
791
799
|
* public currentLocalizedText: LocalizedText
|
|
792
800
|
* }
|
|
@@ -1955,11 +1963,11 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1955
1963
|
const value = preloadOnStatements[key];
|
|
1956
1964
|
if (value === undefined)
|
|
1957
1965
|
throw new UnexpectedUndefined_js_1.default();
|
|
1958
|
-
// filter out plain objects, but not ops and not
|
|
1966
|
+
// filter out plain objects, but not ops and not and/andNot/andAny statements
|
|
1959
1967
|
// because plain objects are just the next level of nested preload
|
|
1960
|
-
if (key === '
|
|
1961
|
-
key === '
|
|
1962
|
-
key === '
|
|
1968
|
+
if (key === 'and' ||
|
|
1969
|
+
key === 'andNot' ||
|
|
1970
|
+
key === 'andAny' ||
|
|
1963
1971
|
value === null ||
|
|
1964
1972
|
value.constructor !== Object) {
|
|
1965
1973
|
agg[key] = value;
|
|
@@ -2048,9 +2056,9 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2048
2056
|
}
|
|
2049
2057
|
}
|
|
2050
2058
|
}
|
|
2051
|
-
applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias,
|
|
2059
|
+
applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias, joinAndStatements = {}, throughAssociations = [], joinType, }) {
|
|
2052
2060
|
const { name, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(currentAssociationTableOrAlias);
|
|
2053
|
-
const
|
|
2061
|
+
const joinAndStatement = joinAndStatements[currentAssociationTableOrAlias];
|
|
2054
2062
|
previousAssociationTableOrAlias = (0, extractAssociationMetadataFromAssociationName_js_1.default)(previousAssociationTableOrAlias).alias;
|
|
2055
2063
|
currentAssociationTableOrAlias = alias;
|
|
2056
2064
|
let association = dreamClass['getAssociationMetadata'](name);
|
|
@@ -2124,12 +2132,12 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2124
2132
|
join = join.onRef(this.namespaceColumn(association.foreignKey(), previousAssociationTableOrAlias), '=', this.namespaceColumn(association.primaryKey(), currentAssociationTableOrAlias));
|
|
2125
2133
|
if (timeToApplyThroughAssociations) {
|
|
2126
2134
|
throughAssociations.forEach((throughAssociation) => {
|
|
2127
|
-
join = this.
|
|
2135
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2128
2136
|
join,
|
|
2129
2137
|
association: throughAssociation,
|
|
2130
2138
|
currentAssociationTableOrAlias,
|
|
2131
2139
|
previousAssociationTableOrAlias: originalPreviousAssociationTableOrAlias,
|
|
2132
|
-
|
|
2140
|
+
joinAndStatements,
|
|
2133
2141
|
});
|
|
2134
2142
|
});
|
|
2135
2143
|
}
|
|
@@ -2138,7 +2146,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2138
2146
|
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2139
2147
|
association,
|
|
2140
2148
|
});
|
|
2141
|
-
join = this.
|
|
2149
|
+
join = this.applyJoinAndStatement(join, joinAndStatement, currentAssociationTableOrAlias);
|
|
2142
2150
|
return join;
|
|
2143
2151
|
});
|
|
2144
2152
|
}
|
|
@@ -2158,28 +2166,28 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2158
2166
|
}
|
|
2159
2167
|
if (timeToApplyThroughAssociations) {
|
|
2160
2168
|
throughAssociations.forEach((throughAssociation) => {
|
|
2161
|
-
join = this.
|
|
2169
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2162
2170
|
join,
|
|
2163
2171
|
association: throughAssociation,
|
|
2164
2172
|
currentAssociationTableOrAlias,
|
|
2165
2173
|
previousAssociationTableOrAlias: originalPreviousAssociationTableOrAlias,
|
|
2166
|
-
|
|
2174
|
+
joinAndStatements,
|
|
2167
2175
|
});
|
|
2168
2176
|
});
|
|
2169
2177
|
}
|
|
2170
|
-
join = this.
|
|
2178
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2171
2179
|
join,
|
|
2172
2180
|
association,
|
|
2173
2181
|
currentAssociationTableOrAlias,
|
|
2174
2182
|
previousAssociationTableOrAlias,
|
|
2175
|
-
|
|
2183
|
+
joinAndStatements,
|
|
2176
2184
|
});
|
|
2177
2185
|
join = this.conditionallyApplyDefaultScopesDependentOnAssociation({
|
|
2178
2186
|
join,
|
|
2179
2187
|
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2180
2188
|
association,
|
|
2181
2189
|
});
|
|
2182
|
-
join = this.
|
|
2190
|
+
join = this.applyJoinAndStatement(join, joinAndStatement, currentAssociationTableOrAlias);
|
|
2183
2191
|
return join;
|
|
2184
2192
|
});
|
|
2185
2193
|
if (association.type === 'HasMany') {
|
|
@@ -2206,29 +2214,29 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2206
2214
|
currentAssociationTableOrAlias,
|
|
2207
2215
|
};
|
|
2208
2216
|
}
|
|
2209
|
-
|
|
2210
|
-
if (association.
|
|
2211
|
-
this.throwUnlessAllRequiredWhereClausesProvided(association, currentAssociationTableOrAlias,
|
|
2212
|
-
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.
|
|
2217
|
+
applyAssociationAndStatementsToJoinStatement({ join, currentAssociationTableOrAlias, previousAssociationTableOrAlias, association, joinAndStatements, }) {
|
|
2218
|
+
if (association.and) {
|
|
2219
|
+
this.throwUnlessAllRequiredWhereClausesProvided(association, currentAssociationTableOrAlias, joinAndStatements);
|
|
2220
|
+
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.and, currentAssociationTableOrAlias), { disallowSimilarityOperator: false }));
|
|
2213
2221
|
}
|
|
2214
|
-
if (association.
|
|
2215
|
-
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.
|
|
2222
|
+
if (association.andNot) {
|
|
2223
|
+
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.andNot, currentAssociationTableOrAlias), { negate: true }));
|
|
2216
2224
|
}
|
|
2217
|
-
if (association.
|
|
2218
|
-
join = join.on((eb) => eb.or(association.
|
|
2225
|
+
if (association.andAny) {
|
|
2226
|
+
join = join.on((eb) => eb.or(association.andAny.map(whereAnyStatement => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(whereAnyStatement, currentAssociationTableOrAlias), { disallowSimilarityOperator: false }))));
|
|
2219
2227
|
}
|
|
2220
|
-
if (association.
|
|
2228
|
+
if (association.selfAnd) {
|
|
2221
2229
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
|
|
2222
2230
|
associationAlias: association.as,
|
|
2223
2231
|
selfAlias: previousAssociationTableOrAlias,
|
|
2224
|
-
|
|
2232
|
+
selfAndClause: association.selfAnd,
|
|
2225
2233
|
})));
|
|
2226
2234
|
}
|
|
2227
|
-
if (association.
|
|
2235
|
+
if (association.selfAndNot) {
|
|
2228
2236
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
|
|
2229
2237
|
associationAlias: association.as,
|
|
2230
2238
|
selfAlias: previousAssociationTableOrAlias,
|
|
2231
|
-
|
|
2239
|
+
selfAndClause: association.selfAndNot,
|
|
2232
2240
|
}), { negate: true }));
|
|
2233
2241
|
}
|
|
2234
2242
|
return join;
|
|
@@ -2263,22 +2271,22 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2263
2271
|
return this.namespaceColumn(foreignKey, tableNameOrAlias);
|
|
2264
2272
|
return this.namespaceColumn(association.distinct, tableNameOrAlias);
|
|
2265
2273
|
}
|
|
2266
|
-
recursivelyJoin({ query,
|
|
2267
|
-
for (const currentAssociationTableOrAlias of Object.keys(
|
|
2274
|
+
recursivelyJoin({ query, joinStatement, joinAndStatements, dreamClass, previousAssociationTableOrAlias, joinType, }) {
|
|
2275
|
+
for (const currentAssociationTableOrAlias of Object.keys(joinStatement)) {
|
|
2268
2276
|
const results = this.applyOneJoin({
|
|
2269
2277
|
query,
|
|
2270
2278
|
dreamClass,
|
|
2271
2279
|
previousAssociationTableOrAlias,
|
|
2272
2280
|
currentAssociationTableOrAlias,
|
|
2273
|
-
|
|
2281
|
+
joinAndStatements,
|
|
2274
2282
|
joinType,
|
|
2275
2283
|
});
|
|
2276
2284
|
query = results.query;
|
|
2277
2285
|
const association = results.association;
|
|
2278
2286
|
query = this.recursivelyJoin({
|
|
2279
2287
|
query,
|
|
2280
|
-
|
|
2281
|
-
|
|
2288
|
+
joinStatement: joinStatement[currentAssociationTableOrAlias],
|
|
2289
|
+
joinAndStatements: joinAndStatements[currentAssociationTableOrAlias],
|
|
2282
2290
|
dreamClass: association.modelCB(),
|
|
2283
2291
|
previousAssociationTableOrAlias: currentAssociationTableOrAlias,
|
|
2284
2292
|
joinType,
|
|
@@ -2286,16 +2294,16 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2286
2294
|
}
|
|
2287
2295
|
return query;
|
|
2288
2296
|
}
|
|
2289
|
-
throwUnlessAllRequiredWhereClausesProvided(association, namespace,
|
|
2290
|
-
const
|
|
2291
|
-
const
|
|
2292
|
-
if (
|
|
2297
|
+
throwUnlessAllRequiredWhereClausesProvided(association, namespace, joinAndStatements) {
|
|
2298
|
+
const andClause = association.and;
|
|
2299
|
+
const columnsRequiringAndStatements = Object.keys(andClause).reduce((agg, column) => {
|
|
2300
|
+
if (andClause[column] === constants_js_1.DreamConst.required)
|
|
2293
2301
|
agg.push(column);
|
|
2294
2302
|
return agg;
|
|
2295
2303
|
}, []);
|
|
2296
|
-
const missingRequiredWhereStatements =
|
|
2304
|
+
const missingRequiredWhereStatements = columnsRequiringAndStatements.filter(column => joinAndStatements[namespace]?.and?.[column] === undefined);
|
|
2297
2305
|
if (missingRequiredWhereStatements.length)
|
|
2298
|
-
throw new
|
|
2306
|
+
throw new MissingRequiredAssociationAndClause_js_1.default(association, missingRequiredWhereStatements[0]);
|
|
2299
2307
|
}
|
|
2300
2308
|
applyOrderStatementForAssociation({ query, tableNameOrAlias, association, }) {
|
|
2301
2309
|
if (!query.orderBy)
|
|
@@ -2423,7 +2431,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2423
2431
|
else if (val === constants_js_1.DreamConst.passthrough) {
|
|
2424
2432
|
const column = attr.split('.').pop();
|
|
2425
2433
|
if (this.passthroughOnStatement[column] === undefined)
|
|
2426
|
-
throw new
|
|
2434
|
+
throw new MissingRequiredPassthroughForAssociationAndClause_js_1.default(column);
|
|
2427
2435
|
val = this.passthroughOnStatement[column];
|
|
2428
2436
|
}
|
|
2429
2437
|
if (val === null) {
|
|
@@ -2490,36 +2498,36 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2490
2498
|
throw new CannotPassUndefinedAsAValueToAWhereClause_js_1.default(this.dreamClass, a2);
|
|
2491
2499
|
return { a, b, c, a2, b2, c2 };
|
|
2492
2500
|
}
|
|
2493
|
-
|
|
2494
|
-
if (!
|
|
2501
|
+
applyJoinAndStatement(join, joinAndStatement, rootTableOrAssociationAlias) {
|
|
2502
|
+
if (!joinAndStatement)
|
|
2495
2503
|
return join;
|
|
2496
|
-
join = this.
|
|
2497
|
-
join = this.
|
|
2504
|
+
join = this._applyJoinAndStatements(join, joinAndStatement.and, rootTableOrAssociationAlias);
|
|
2505
|
+
join = this._applyJoinAndStatements(join, joinAndStatement.andNot, rootTableOrAssociationAlias, {
|
|
2498
2506
|
negate: true,
|
|
2499
2507
|
});
|
|
2500
|
-
join = this.
|
|
2508
|
+
join = this._applyJoinAndAnyStatements(join, joinAndStatement.andAny, rootTableOrAssociationAlias);
|
|
2501
2509
|
return join;
|
|
2502
2510
|
}
|
|
2503
|
-
|
|
2504
|
-
if (!
|
|
2511
|
+
_applyJoinAndStatements(join, joinAndStatement, rootTableOrAssociationAlias, { negate = false, } = {}) {
|
|
2512
|
+
if (!joinAndStatement)
|
|
2505
2513
|
return join;
|
|
2506
|
-
return join.on((eb) => this.
|
|
2514
|
+
return join.on((eb) => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, {
|
|
2507
2515
|
negate,
|
|
2508
2516
|
disallowSimilarityOperator: negate,
|
|
2509
2517
|
}));
|
|
2510
2518
|
}
|
|
2511
|
-
|
|
2512
|
-
if (!
|
|
2519
|
+
_applyJoinAndAnyStatements(join, joinAndAnyStatement, rootTableOrAssociationAlias) {
|
|
2520
|
+
if (!joinAndAnyStatement)
|
|
2513
2521
|
return join;
|
|
2514
|
-
if (!
|
|
2522
|
+
if (!joinAndAnyStatement.length)
|
|
2515
2523
|
return join;
|
|
2516
2524
|
return join.on((eb) => {
|
|
2517
|
-
return eb.or(
|
|
2525
|
+
return eb.or(joinAndAnyStatement.map(joinAndStatement => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb)));
|
|
2518
2526
|
});
|
|
2519
2527
|
}
|
|
2520
|
-
|
|
2521
|
-
return this.whereStatementToExpressionWrapper(eb, Object.keys(
|
|
2522
|
-
agg[this.namespaceColumn(key.toString(), rootTableOrAssociationAlias)] =
|
|
2528
|
+
joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, { negate = false, disallowSimilarityOperator = true, } = {}) {
|
|
2529
|
+
return this.whereStatementToExpressionWrapper(eb, Object.keys(joinAndStatement).reduce((agg, key) => {
|
|
2530
|
+
agg[this.namespaceColumn(key.toString(), rootTableOrAssociationAlias)] = joinAndStatement[key];
|
|
2523
2531
|
return agg;
|
|
2524
2532
|
}, {}), {
|
|
2525
2533
|
negate,
|
|
@@ -2532,8 +2540,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2532
2540
|
if (!(0, isEmpty_js_1.default)(query.innerJoinStatements)) {
|
|
2533
2541
|
kyselyQuery = query.recursivelyJoin({
|
|
2534
2542
|
query: kyselyQuery,
|
|
2535
|
-
|
|
2536
|
-
|
|
2543
|
+
joinStatement: query.innerJoinStatements,
|
|
2544
|
+
joinAndStatements: query.innerJoinAndStatements,
|
|
2537
2545
|
dreamClass: query.dreamClass,
|
|
2538
2546
|
previousAssociationTableOrAlias: this.baseSqlAlias,
|
|
2539
2547
|
joinType: 'inner',
|
|
@@ -2542,8 +2550,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2542
2550
|
if (!(0, isEmpty_js_1.default)(query.leftJoinStatements)) {
|
|
2543
2551
|
kyselyQuery = query.recursivelyJoin({
|
|
2544
2552
|
query: kyselyQuery,
|
|
2545
|
-
|
|
2546
|
-
|
|
2553
|
+
joinStatement: query.leftJoinStatements,
|
|
2554
|
+
joinAndStatements: query.leftJoinAndStatements,
|
|
2547
2555
|
dreamClass: query.dreamClass,
|
|
2548
2556
|
previousAssociationTableOrAlias: this.baseSqlAlias,
|
|
2549
2557
|
joinType: 'left',
|
|
@@ -2579,11 +2587,11 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2579
2587
|
return aliasedWhere;
|
|
2580
2588
|
}, {});
|
|
2581
2589
|
}
|
|
2582
|
-
rawifiedSelfOnClause({ associationAlias, selfAlias,
|
|
2590
|
+
rawifiedSelfOnClause({ associationAlias, selfAlias, selfAndClause, }) {
|
|
2583
2591
|
const alphanumericUnderscoreRegexp = /[^a-zA-Z0-9_]/g;
|
|
2584
2592
|
selfAlias = selfAlias.replace(alphanumericUnderscoreRegexp, '');
|
|
2585
|
-
return Object.keys(
|
|
2586
|
-
const selfColumn =
|
|
2593
|
+
return Object.keys(selfAndClause).reduce((acc, key) => {
|
|
2594
|
+
const selfColumn = selfAndClause[key]?.replace(alphanumericUnderscoreRegexp, '');
|
|
2587
2595
|
if (!selfColumn)
|
|
2588
2596
|
return acc;
|
|
2589
2597
|
acc[this.namespaceColumn(key, associationAlias)] = kysely_1.sql.raw(`"${(0, snakeify_js_1.default)(selfAlias)}"."${(0, snakeify_js_1.default)(selfColumn)}"`);
|
|
@@ -2661,7 +2669,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2661
2669
|
return new SimilarityBuilder_js_1.default(this.dreamInstance, {
|
|
2662
2670
|
where: [...this.whereStatements],
|
|
2663
2671
|
whereNot: [...this.whereNotStatements],
|
|
2664
|
-
|
|
2672
|
+
joinAndStatements: this.innerJoinAndStatements,
|
|
2665
2673
|
transaction: this.dreamTransaction,
|
|
2666
2674
|
connection: this.connectionOverride,
|
|
2667
2675
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = associationQuery;
|
|
4
4
|
const applyScopeBypassingSettingsToQuery_js_1 = require("../applyScopeBypassingSettingsToQuery.js");
|
|
5
|
-
function associationQuery(dream, txn = null, associationName, {
|
|
5
|
+
function associationQuery(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
6
6
|
const association = dream['associationMetadataMap']()[associationName];
|
|
7
7
|
const associationClass = association.modelCB();
|
|
8
8
|
const dreamClass = dream.constructor;
|
|
@@ -10,8 +10,8 @@ function associationQuery(dream, txn = null, associationName, { joinOnStatements
|
|
|
10
10
|
let baseSelectQuery = dreamClassOrTransaction.where({
|
|
11
11
|
[dream.primaryKey]: dream.primaryKeyValue,
|
|
12
12
|
});
|
|
13
|
-
if (
|
|
14
|
-
baseSelectQuery = baseSelectQuery.innerJoin(association.as,
|
|
13
|
+
if (joinAndStatements && (joinAndStatements.and || joinAndStatements.andNot || joinAndStatements.andAny))
|
|
14
|
+
baseSelectQuery = baseSelectQuery.innerJoin(association.as, joinAndStatements);
|
|
15
15
|
else
|
|
16
16
|
baseSelectQuery = baseSelectQuery.innerJoin(association.as);
|
|
17
17
|
let query = txn ? associationClass.txn(txn).queryInstance() : associationClass.query();
|
|
@@ -4,7 +4,7 @@ exports.default = associationUpdateQuery;
|
|
|
4
4
|
const UnexpectedUndefined_js_1 = require("../../../errors/UnexpectedUndefined.js");
|
|
5
5
|
const namespaceColumn_js_1 = require("../../../helpers/namespaceColumn.js");
|
|
6
6
|
const applyScopeBypassingSettingsToQuery_js_1 = require("../applyScopeBypassingSettingsToQuery.js");
|
|
7
|
-
function associationUpdateQuery(dream, txn = null, associationName, {
|
|
7
|
+
function associationUpdateQuery(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
8
8
|
const association = dream['associationMetadataMap']()[associationName];
|
|
9
9
|
if (association === undefined)
|
|
10
10
|
throw new UnexpectedUndefined_js_1.default();
|
|
@@ -20,8 +20,8 @@ function associationUpdateQuery(dream, txn = null, associationName, { joinOnStat
|
|
|
20
20
|
bypassAllDefaultScopes,
|
|
21
21
|
defaultScopesToBypass,
|
|
22
22
|
});
|
|
23
|
-
if (
|
|
24
|
-
nestedScope = nestedScope.innerJoin(association.as,
|
|
23
|
+
if (joinAndStatements && (joinAndStatements.and || joinAndStatements.andNot || joinAndStatements.andAny))
|
|
24
|
+
nestedScope = nestedScope.innerJoin(association.as, joinAndStatements);
|
|
25
25
|
else
|
|
26
26
|
nestedScope = nestedScope.innerJoin(association.as);
|
|
27
27
|
const nestedSelect = nestedScope
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = destroyAssociation;
|
|
4
4
|
const associationUpdateQuery_js_1 = require("./associationUpdateQuery.js");
|
|
5
|
-
async function destroyAssociation(dream, txn = null, associationName, {
|
|
5
|
+
async function destroyAssociation(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, cascade, reallyDestroy, skipHooks, }) {
|
|
6
6
|
const query = (0, associationUpdateQuery_js_1.default)(dream, txn, associationName, {
|
|
7
|
-
|
|
7
|
+
joinAndStatements,
|
|
8
8
|
bypassAllDefaultScopes,
|
|
9
9
|
defaultScopesToBypass,
|
|
10
10
|
});
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = undestroyAssociation;
|
|
4
4
|
const associationUpdateQuery_js_1 = require("./associationUpdateQuery.js");
|
|
5
|
-
async function undestroyAssociation(dream, txn = null, associationName, {
|
|
5
|
+
async function undestroyAssociation(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, cascade, skipHooks, }) {
|
|
6
6
|
const query = (0, associationUpdateQuery_js_1.default)(dream, txn, associationName, {
|
|
7
|
-
|
|
7
|
+
joinAndStatements,
|
|
8
8
|
bypassAllDefaultScopes,
|
|
9
9
|
defaultScopesToBypass,
|
|
10
10
|
});
|
|
@@ -14,12 +14,12 @@ const similarityWhereSql_js_1 = require("./similarityWhereSql.js");
|
|
|
14
14
|
class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
15
15
|
whereStatement;
|
|
16
16
|
whereNotStatement;
|
|
17
|
-
|
|
17
|
+
joinAndStatements = Object.freeze({});
|
|
18
18
|
constructor(dreamInstance, opts = {}) {
|
|
19
19
|
super(dreamInstance, opts);
|
|
20
20
|
this.whereStatement = Object.freeze(opts.where || []);
|
|
21
21
|
this.whereNotStatement = Object.freeze(opts.whereNot || []);
|
|
22
|
-
this.
|
|
22
|
+
this.joinAndStatements = Object.freeze(opts.joinAndStatements || {});
|
|
23
23
|
}
|
|
24
24
|
/*
|
|
25
25
|
#select
|
|
@@ -73,11 +73,11 @@ class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
|
73
73
|
bypassOrder,
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
|
-
this.
|
|
76
|
+
this.joinAndStatementsWithSimilarityClauses().forEach((similarityStatement, index) => {
|
|
77
77
|
kyselyQuery = this.addStatementToSelectQuery({
|
|
78
78
|
kyselyQuery,
|
|
79
79
|
similarityStatement,
|
|
80
|
-
statementType: '
|
|
80
|
+
statementType: 'join_and',
|
|
81
81
|
index,
|
|
82
82
|
bypassOrder,
|
|
83
83
|
});
|
|
@@ -148,11 +148,11 @@ class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
|
148
148
|
index,
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
|
-
this.
|
|
151
|
+
this.joinAndStatementsWithSimilarityClauses().forEach((similarityStatement, index) => {
|
|
152
152
|
kyselyQuery = this.addStatementToUpdateQuery({
|
|
153
153
|
kyselyQuery,
|
|
154
154
|
similarityStatement,
|
|
155
|
-
statementType: '
|
|
155
|
+
statementType: 'join_and',
|
|
156
156
|
index,
|
|
157
157
|
});
|
|
158
158
|
});
|
|
@@ -167,8 +167,8 @@ class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
|
167
167
|
whereNotStatementsWithSimilarityClauses() {
|
|
168
168
|
return this.similarityStatementFilter(this.whereNotStatement);
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
return this.recursiveJoinsOnFinder(
|
|
170
|
+
joinAndStatementsWithSimilarityClauses() {
|
|
171
|
+
return this.recursiveJoinsOnFinder(removeJoinAndFromObjectHierarchy(this.joinAndStatements), this.dreamClass);
|
|
172
172
|
}
|
|
173
173
|
recursiveJoinsOnFinder(obj, dreamClass) {
|
|
174
174
|
const similar = [];
|
|
@@ -210,7 +210,7 @@ class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
|
210
210
|
return [
|
|
211
211
|
...this.whereStatementsWithSimilarityClauses(),
|
|
212
212
|
...this.whereNotStatementsWithSimilarityClauses(),
|
|
213
|
-
...this.
|
|
213
|
+
...this.joinAndStatementsWithSimilarityClauses(),
|
|
214
214
|
];
|
|
215
215
|
}
|
|
216
216
|
addStatementToSelectQuery({ kyselyQuery, similarityStatement, index, statementType, bypassOrder, }) {
|
|
@@ -312,15 +312,15 @@ class SimilarityBuilder extends ConnectedToDB_js_1.default {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
exports.default = SimilarityBuilder;
|
|
315
|
-
exports.SIMILARITY_TYPES = ['where', '
|
|
316
|
-
function
|
|
315
|
+
exports.SIMILARITY_TYPES = ['where', 'join_and'];
|
|
316
|
+
function removeJoinAndFromObjectHierarchy(obj) {
|
|
317
317
|
if (obj?.isOpsStatement)
|
|
318
318
|
return obj;
|
|
319
319
|
const result = {};
|
|
320
320
|
for (const key in obj) {
|
|
321
321
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
322
322
|
if ((0, typechecks_js_1.isObject)(obj[key])) {
|
|
323
|
-
result[key] =
|
|
323
|
+
result[key] = removeJoinAndFromObjectHierarchy(obj[key].and || obj[key]);
|
|
324
324
|
}
|
|
325
325
|
else {
|
|
326
326
|
result[key] = obj[key];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class
|
|
3
|
+
class CannotDefineAssociationWithBothDependentAndRequiredAndClause extends Error {
|
|
4
4
|
dreamClass;
|
|
5
5
|
associationName;
|
|
6
6
|
constructor(dreamClass, associationName) {
|
|
@@ -16,4 +16,4 @@ ${this.dreamClass.sanitizedName} dream class.
|
|
|
16
16
|
`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
exports.default =
|
|
19
|
+
exports.default = CannotDefineAssociationWithBothDependentAndRequiredAndClause;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class
|
|
3
|
+
class MissingRequiredAssociationAndClause extends Error {
|
|
4
4
|
association;
|
|
5
5
|
column;
|
|
6
6
|
constructor(association, column) {
|
|
@@ -10,10 +10,10 @@ class MissingRequiredAssociationOnClause extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
get message() {
|
|
12
12
|
return `
|
|
13
|
-
Missing required association
|
|
13
|
+
Missing required association and-clause:
|
|
14
14
|
Association: ${this.association.as}
|
|
15
|
-
Missing
|
|
15
|
+
Missing and-clause for column: ${this.column}
|
|
16
16
|
`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
exports.default =
|
|
19
|
+
exports.default = MissingRequiredAssociationAndClause;
|