@rvoh/dream 0.36.4 → 0.38.0
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 +42 -32
- 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 +42 -32
- 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 +25 -21
- 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/assets/search.js +1 -1
- 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 +170 -163
- 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
|
@@ -7,8 +7,8 @@ import AssociationDeclaredWithoutAssociatedDreamClass from '../errors/associatio
|
|
|
7
7
|
import CannotAssociateThroughPolymorphic from '../errors/associations/CannotAssociateThroughPolymorphic.js';
|
|
8
8
|
import CannotJoinPolymorphicBelongsToError from '../errors/associations/CannotJoinPolymorphicBelongsToError.js';
|
|
9
9
|
import JoinAttemptedOnMissingAssociation from '../errors/associations/JoinAttemptedOnMissingAssociation.js';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import MissingRequiredAssociationAndClause from '../errors/associations/MissingRequiredAssociationAndClause.js';
|
|
11
|
+
import MissingRequiredPassthroughForAssociationAndClause from '../errors/associations/MissingRequiredPassthroughForAssociationAndClause.js';
|
|
12
12
|
import MissingThroughAssociation from '../errors/associations/MissingThroughAssociation.js';
|
|
13
13
|
import MissingThroughAssociationSource from '../errors/associations/MissingThroughAssociationSource.js';
|
|
14
14
|
import CannotCallUndestroyOnANonSoftDeleteModel from '../errors/CannotCallUndestroyOnANonSoftDeleteModel.js';
|
|
@@ -150,7 +150,7 @@ export default class Query extends ConnectedToDB {
|
|
|
150
150
|
* stores the joins on statements applied to the
|
|
151
151
|
* current Query instance
|
|
152
152
|
*/
|
|
153
|
-
|
|
153
|
+
innerJoinAndStatements = Object.freeze({});
|
|
154
154
|
/**
|
|
155
155
|
* @internal
|
|
156
156
|
*
|
|
@@ -164,7 +164,7 @@ export default class Query extends ConnectedToDB {
|
|
|
164
164
|
* stores the joins on statements applied to the
|
|
165
165
|
* current Query instance
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
leftJoinAndStatements = Object.freeze({});
|
|
168
168
|
/**
|
|
169
169
|
* @internal
|
|
170
170
|
*
|
|
@@ -234,9 +234,9 @@ export default class Query extends ConnectedToDB {
|
|
|
234
234
|
this.preloadStatements = Object.freeze(opts.preloadStatements || {});
|
|
235
235
|
this.preloadOnStatements = Object.freeze(opts.preloadOnStatements || {});
|
|
236
236
|
this.innerJoinStatements = Object.freeze(opts.innerJoinStatements || {});
|
|
237
|
-
this.
|
|
237
|
+
this.innerJoinAndStatements = Object.freeze(opts.innerJoinAndStatements || {});
|
|
238
238
|
this.leftJoinStatements = Object.freeze(opts.leftJoinStatements || {});
|
|
239
|
-
this.
|
|
239
|
+
this.leftJoinAndStatements = Object.freeze(opts.leftJoinAndStatements || {});
|
|
240
240
|
this.baseSqlAlias = opts.baseSqlAlias || this.tableName;
|
|
241
241
|
this.baseSelectQuery = opts.baseSelectQuery || null;
|
|
242
242
|
this.limitStatement = opts.limit || null;
|
|
@@ -308,16 +308,16 @@ export default class Query extends ConnectedToDB {
|
|
|
308
308
|
order: opts.order === null ? [] : [...this.orderStatements, ...(opts.order || [])],
|
|
309
309
|
distinctColumn: opts.distinctColumn !== undefined ? opts.distinctColumn : this.distinctColumn,
|
|
310
310
|
loadFromJoins: opts.loadFromJoins !== undefined ? opts.loadFromJoins : this.joinLoadActivated,
|
|
311
|
-
// when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and
|
|
311
|
+
// when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and innerJoinAndStatements are already
|
|
312
312
|
// cloned versions of the `this.` versions, handled in the `preload` and `joins` methods
|
|
313
313
|
preloadStatements: opts.preloadStatements || this.preloadStatements,
|
|
314
314
|
preloadOnStatements: opts.preloadOnStatements || this.preloadOnStatements,
|
|
315
315
|
innerJoinDreamClasses: opts.innerJoinDreamClasses || this.innerJoinDreamClasses,
|
|
316
316
|
innerJoinStatements: opts.innerJoinStatements || this.innerJoinStatements,
|
|
317
|
-
|
|
317
|
+
innerJoinAndStatements: opts.innerJoinAndStatements || this.innerJoinAndStatements,
|
|
318
318
|
leftJoinStatements: opts.leftJoinStatements || this.leftJoinStatements,
|
|
319
|
-
|
|
320
|
-
// end:when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and
|
|
319
|
+
leftJoinAndStatements: opts.leftJoinAndStatements || this.leftJoinAndStatements,
|
|
320
|
+
// end:when passed, preloadStatements, preloadOnStatements, innerJoinStatements, and innerJoinAndStatements are already...
|
|
321
321
|
bypassAllDefaultScopes: opts.bypassAllDefaultScopes !== undefined ? opts.bypassAllDefaultScopes : this.bypassAllDefaultScopes,
|
|
322
322
|
bypassAllDefaultScopesExceptOnAssociations: opts.bypassAllDefaultScopesExceptOnAssociations !== undefined
|
|
323
323
|
? opts.bypassAllDefaultScopesExceptOnAssociations
|
|
@@ -463,7 +463,7 @@ export default class Query extends ConnectedToDB {
|
|
|
463
463
|
* // [Reply{id: 1}, Reply{id: 2}]
|
|
464
464
|
* ```
|
|
465
465
|
*
|
|
466
|
-
* @param args - A chain of association names and
|
|
466
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
467
467
|
* @returns A cloned Query with the joinLoad statement applied
|
|
468
468
|
*/
|
|
469
469
|
leftJoinPreload(...args) {
|
|
@@ -485,7 +485,7 @@ export default class Query extends ConnectedToDB {
|
|
|
485
485
|
* // [Reply{id: 1}, Reply{id: 2}]
|
|
486
486
|
* ```
|
|
487
487
|
*
|
|
488
|
-
* @param args - A chain of association names and
|
|
488
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
489
489
|
* @returns A cloned Query with the preload statement applied
|
|
490
490
|
*/
|
|
491
491
|
preload(...args) {
|
|
@@ -502,36 +502,44 @@ export default class Query extends ConnectedToDB {
|
|
|
502
502
|
* await User.query().innerJoin('posts').first()
|
|
503
503
|
* ```
|
|
504
504
|
*
|
|
505
|
-
* @param args - A chain of association names and
|
|
505
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
506
506
|
* @returns A cloned Query with the joins clause applied
|
|
507
507
|
*/
|
|
508
508
|
innerJoin(...args) {
|
|
509
509
|
const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
|
|
510
510
|
const innerJoinStatements = cloneDeepSafe(this.innerJoinStatements);
|
|
511
|
-
const
|
|
512
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, innerJoinStatements,
|
|
513
|
-
return this.clone({
|
|
511
|
+
const innerJoinAndStatements = cloneDeepSafe(this.innerJoinAndStatements);
|
|
512
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, innerJoinStatements, innerJoinAndStatements, null, [...args]);
|
|
513
|
+
return this.clone({
|
|
514
|
+
innerJoinDreamClasses,
|
|
515
|
+
innerJoinStatements,
|
|
516
|
+
innerJoinAndStatements,
|
|
517
|
+
});
|
|
514
518
|
}
|
|
515
519
|
/**
|
|
516
520
|
* @internal
|
|
517
521
|
*
|
|
518
|
-
* @param args - A chain of association names and
|
|
522
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
519
523
|
* @returns A cloned Query with the joins clause applied
|
|
520
524
|
*/
|
|
521
525
|
leftJoin(...args) {
|
|
522
526
|
const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
|
|
523
527
|
const leftJoinStatements = cloneDeepSafe(this.leftJoinStatements);
|
|
524
|
-
const
|
|
525
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, leftJoinStatements,
|
|
528
|
+
const leftJoinAndStatements = cloneDeepSafe(this.leftJoinAndStatements);
|
|
529
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, leftJoinStatements, leftJoinAndStatements, null, [
|
|
526
530
|
...args,
|
|
527
531
|
]);
|
|
528
|
-
return this.clone({
|
|
532
|
+
return this.clone({
|
|
533
|
+
innerJoinDreamClasses,
|
|
534
|
+
leftJoinStatements,
|
|
535
|
+
leftJoinAndStatements,
|
|
536
|
+
});
|
|
529
537
|
}
|
|
530
538
|
/**
|
|
531
539
|
* @internal
|
|
532
540
|
*
|
|
533
541
|
*/
|
|
534
|
-
fleshOutJoinStatements(innerJoinDreamClasses, joinStatements,
|
|
542
|
+
fleshOutJoinStatements(innerJoinDreamClasses, joinStatements, joinAndStatements, previousAssociationName, associationStatements, previousDreamClass = this.dreamClass) {
|
|
535
543
|
const nextAssociationStatement = associationStatements.shift();
|
|
536
544
|
if (nextAssociationStatement === undefined) {
|
|
537
545
|
// just satisfying typing
|
|
@@ -540,11 +548,11 @@ export default class Query extends ConnectedToDB {
|
|
|
540
548
|
const nextStatement = nextAssociationStatement;
|
|
541
549
|
if (!joinStatements[nextStatement])
|
|
542
550
|
joinStatements[protectAgainstPollutingAssignment(nextStatement)] = {};
|
|
543
|
-
if (!
|
|
544
|
-
|
|
551
|
+
if (!joinAndStatements[nextStatement])
|
|
552
|
+
joinAndStatements[protectAgainstPollutingAssignment(nextStatement)] = {};
|
|
545
553
|
const nextDreamClass = this.addAssociatedDreamClassToInnerJoinDreamClasses(previousDreamClass, nextStatement, innerJoinDreamClasses);
|
|
546
554
|
const nextJoinsStatements = joinStatements[nextStatement];
|
|
547
|
-
const nextJoinsOnStatements =
|
|
555
|
+
const nextJoinsOnStatements = joinAndStatements[nextStatement];
|
|
548
556
|
this.fleshOutJoinStatements(innerJoinDreamClasses, nextJoinsStatements, nextJoinsOnStatements, nextStatement, associationStatements, nextDreamClass);
|
|
549
557
|
//
|
|
550
558
|
}
|
|
@@ -562,9 +570,9 @@ export default class Query extends ConnectedToDB {
|
|
|
562
570
|
const clonedNextAssociationStatement = cloneDeepSafe(nextAssociationStatement);
|
|
563
571
|
const keys = Object.keys(clonedNextAssociationStatement);
|
|
564
572
|
keys.forEach((key) => {
|
|
565
|
-
|
|
573
|
+
joinAndStatements[protectAgainstPollutingAssignment(key)] = clonedNextAssociationStatement[key];
|
|
566
574
|
});
|
|
567
|
-
this.fleshOutJoinStatements(innerJoinDreamClasses, joinStatements,
|
|
575
|
+
this.fleshOutJoinStatements(innerJoinDreamClasses, joinStatements, joinAndStatements, previousAssociationName, associationStatements, previousDreamClass);
|
|
568
576
|
}
|
|
569
577
|
}
|
|
570
578
|
/**
|
|
@@ -784,7 +792,7 @@ export default class Query extends ConnectedToDB {
|
|
|
784
792
|
* public localizedTexts: LocalizedText[]
|
|
785
793
|
*
|
|
786
794
|
* @deco.HasOne('LocalizedText', {
|
|
787
|
-
*
|
|
795
|
+
* and: { locale: DreamConst.passthrough },
|
|
788
796
|
* })
|
|
789
797
|
* public currentLocalizedText: LocalizedText
|
|
790
798
|
* }
|
|
@@ -1953,11 +1961,11 @@ export default class Query extends ConnectedToDB {
|
|
|
1953
1961
|
const value = preloadOnStatements[key];
|
|
1954
1962
|
if (value === undefined)
|
|
1955
1963
|
throw new UnexpectedUndefined();
|
|
1956
|
-
// filter out plain objects, but not ops and not
|
|
1964
|
+
// filter out plain objects, but not ops and not and/andNot/andAny statements
|
|
1957
1965
|
// because plain objects are just the next level of nested preload
|
|
1958
|
-
if (key === '
|
|
1959
|
-
key === '
|
|
1960
|
-
key === '
|
|
1966
|
+
if (key === 'and' ||
|
|
1967
|
+
key === 'andNot' ||
|
|
1968
|
+
key === 'andAny' ||
|
|
1961
1969
|
value === null ||
|
|
1962
1970
|
value.constructor !== Object) {
|
|
1963
1971
|
agg[key] = value;
|
|
@@ -2046,9 +2054,9 @@ export default class Query extends ConnectedToDB {
|
|
|
2046
2054
|
}
|
|
2047
2055
|
}
|
|
2048
2056
|
}
|
|
2049
|
-
applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias,
|
|
2057
|
+
applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias, joinAndStatements = {}, throughAssociations = [], joinType, }) {
|
|
2050
2058
|
const { name, alias } = extractAssociationMetadataFromAssociationName(currentAssociationTableOrAlias);
|
|
2051
|
-
const
|
|
2059
|
+
const joinAndStatement = joinAndStatements[currentAssociationTableOrAlias];
|
|
2052
2060
|
previousAssociationTableOrAlias = extractAssociationMetadataFromAssociationName(previousAssociationTableOrAlias).alias;
|
|
2053
2061
|
currentAssociationTableOrAlias = alias;
|
|
2054
2062
|
let association = dreamClass['getAssociationMetadata'](name);
|
|
@@ -2122,12 +2130,12 @@ export default class Query extends ConnectedToDB {
|
|
|
2122
2130
|
join = join.onRef(this.namespaceColumn(association.foreignKey(), previousAssociationTableOrAlias), '=', this.namespaceColumn(association.primaryKey(), currentAssociationTableOrAlias));
|
|
2123
2131
|
if (timeToApplyThroughAssociations) {
|
|
2124
2132
|
throughAssociations.forEach((throughAssociation) => {
|
|
2125
|
-
join = this.
|
|
2133
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2126
2134
|
join,
|
|
2127
2135
|
association: throughAssociation,
|
|
2128
2136
|
currentAssociationTableOrAlias,
|
|
2129
2137
|
previousAssociationTableOrAlias: originalPreviousAssociationTableOrAlias,
|
|
2130
|
-
|
|
2138
|
+
joinAndStatements,
|
|
2131
2139
|
});
|
|
2132
2140
|
});
|
|
2133
2141
|
}
|
|
@@ -2136,7 +2144,7 @@ export default class Query extends ConnectedToDB {
|
|
|
2136
2144
|
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2137
2145
|
association,
|
|
2138
2146
|
});
|
|
2139
|
-
join = this.
|
|
2147
|
+
join = this.applyJoinAndStatement(join, joinAndStatement, currentAssociationTableOrAlias);
|
|
2140
2148
|
return join;
|
|
2141
2149
|
});
|
|
2142
2150
|
}
|
|
@@ -2156,28 +2164,28 @@ export default class Query extends ConnectedToDB {
|
|
|
2156
2164
|
}
|
|
2157
2165
|
if (timeToApplyThroughAssociations) {
|
|
2158
2166
|
throughAssociations.forEach((throughAssociation) => {
|
|
2159
|
-
join = this.
|
|
2167
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2160
2168
|
join,
|
|
2161
2169
|
association: throughAssociation,
|
|
2162
2170
|
currentAssociationTableOrAlias,
|
|
2163
2171
|
previousAssociationTableOrAlias: originalPreviousAssociationTableOrAlias,
|
|
2164
|
-
|
|
2172
|
+
joinAndStatements,
|
|
2165
2173
|
});
|
|
2166
2174
|
});
|
|
2167
2175
|
}
|
|
2168
|
-
join = this.
|
|
2176
|
+
join = this.applyAssociationAndStatementsToJoinStatement({
|
|
2169
2177
|
join,
|
|
2170
2178
|
association,
|
|
2171
2179
|
currentAssociationTableOrAlias,
|
|
2172
2180
|
previousAssociationTableOrAlias,
|
|
2173
|
-
|
|
2181
|
+
joinAndStatements,
|
|
2174
2182
|
});
|
|
2175
2183
|
join = this.conditionallyApplyDefaultScopesDependentOnAssociation({
|
|
2176
2184
|
join,
|
|
2177
2185
|
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2178
2186
|
association,
|
|
2179
2187
|
});
|
|
2180
|
-
join = this.
|
|
2188
|
+
join = this.applyJoinAndStatement(join, joinAndStatement, currentAssociationTableOrAlias);
|
|
2181
2189
|
return join;
|
|
2182
2190
|
});
|
|
2183
2191
|
if (association.type === 'HasMany') {
|
|
@@ -2204,29 +2212,29 @@ export default class Query extends ConnectedToDB {
|
|
|
2204
2212
|
currentAssociationTableOrAlias,
|
|
2205
2213
|
};
|
|
2206
2214
|
}
|
|
2207
|
-
|
|
2208
|
-
if (association.
|
|
2209
|
-
this.throwUnlessAllRequiredWhereClausesProvided(association, currentAssociationTableOrAlias,
|
|
2210
|
-
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.
|
|
2215
|
+
applyAssociationAndStatementsToJoinStatement({ join, currentAssociationTableOrAlias, previousAssociationTableOrAlias, association, joinAndStatements, }) {
|
|
2216
|
+
if (association.and) {
|
|
2217
|
+
this.throwUnlessAllRequiredWhereClausesProvided(association, currentAssociationTableOrAlias, joinAndStatements);
|
|
2218
|
+
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.and, currentAssociationTableOrAlias), { disallowSimilarityOperator: false }));
|
|
2211
2219
|
}
|
|
2212
|
-
if (association.
|
|
2213
|
-
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.
|
|
2220
|
+
if (association.andNot) {
|
|
2221
|
+
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.andNot, currentAssociationTableOrAlias), { negate: true }));
|
|
2214
2222
|
}
|
|
2215
|
-
if (association.
|
|
2216
|
-
join = join.on((eb) => eb.or(association.
|
|
2223
|
+
if (association.andAny) {
|
|
2224
|
+
join = join.on((eb) => eb.or(association.andAny.map(whereAnyStatement => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(whereAnyStatement, currentAssociationTableOrAlias), { disallowSimilarityOperator: false }))));
|
|
2217
2225
|
}
|
|
2218
|
-
if (association.
|
|
2226
|
+
if (association.selfAnd) {
|
|
2219
2227
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
|
|
2220
2228
|
associationAlias: association.as,
|
|
2221
2229
|
selfAlias: previousAssociationTableOrAlias,
|
|
2222
|
-
|
|
2230
|
+
selfAndClause: association.selfAnd,
|
|
2223
2231
|
})));
|
|
2224
2232
|
}
|
|
2225
|
-
if (association.
|
|
2233
|
+
if (association.selfAndNot) {
|
|
2226
2234
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
|
|
2227
2235
|
associationAlias: association.as,
|
|
2228
2236
|
selfAlias: previousAssociationTableOrAlias,
|
|
2229
|
-
|
|
2237
|
+
selfAndClause: association.selfAndNot,
|
|
2230
2238
|
}), { negate: true }));
|
|
2231
2239
|
}
|
|
2232
2240
|
return join;
|
|
@@ -2261,22 +2269,22 @@ export default class Query extends ConnectedToDB {
|
|
|
2261
2269
|
return this.namespaceColumn(foreignKey, tableNameOrAlias);
|
|
2262
2270
|
return this.namespaceColumn(association.distinct, tableNameOrAlias);
|
|
2263
2271
|
}
|
|
2264
|
-
recursivelyJoin({ query,
|
|
2265
|
-
for (const currentAssociationTableOrAlias of Object.keys(
|
|
2272
|
+
recursivelyJoin({ query, joinStatement, joinAndStatements, dreamClass, previousAssociationTableOrAlias, joinType, }) {
|
|
2273
|
+
for (const currentAssociationTableOrAlias of Object.keys(joinStatement)) {
|
|
2266
2274
|
const results = this.applyOneJoin({
|
|
2267
2275
|
query,
|
|
2268
2276
|
dreamClass,
|
|
2269
2277
|
previousAssociationTableOrAlias,
|
|
2270
2278
|
currentAssociationTableOrAlias,
|
|
2271
|
-
|
|
2279
|
+
joinAndStatements,
|
|
2272
2280
|
joinType,
|
|
2273
2281
|
});
|
|
2274
2282
|
query = results.query;
|
|
2275
2283
|
const association = results.association;
|
|
2276
2284
|
query = this.recursivelyJoin({
|
|
2277
2285
|
query,
|
|
2278
|
-
|
|
2279
|
-
|
|
2286
|
+
joinStatement: joinStatement[currentAssociationTableOrAlias],
|
|
2287
|
+
joinAndStatements: joinAndStatements[currentAssociationTableOrAlias],
|
|
2280
2288
|
dreamClass: association.modelCB(),
|
|
2281
2289
|
previousAssociationTableOrAlias: currentAssociationTableOrAlias,
|
|
2282
2290
|
joinType,
|
|
@@ -2284,16 +2292,16 @@ export default class Query extends ConnectedToDB {
|
|
|
2284
2292
|
}
|
|
2285
2293
|
return query;
|
|
2286
2294
|
}
|
|
2287
|
-
throwUnlessAllRequiredWhereClausesProvided(association, namespace,
|
|
2288
|
-
const
|
|
2289
|
-
const
|
|
2290
|
-
if (
|
|
2295
|
+
throwUnlessAllRequiredWhereClausesProvided(association, namespace, joinAndStatements) {
|
|
2296
|
+
const andClause = association.and;
|
|
2297
|
+
const columnsRequiringAndStatements = Object.keys(andClause).reduce((agg, column) => {
|
|
2298
|
+
if (andClause[column] === DreamConst.required)
|
|
2291
2299
|
agg.push(column);
|
|
2292
2300
|
return agg;
|
|
2293
2301
|
}, []);
|
|
2294
|
-
const missingRequiredWhereStatements =
|
|
2302
|
+
const missingRequiredWhereStatements = columnsRequiringAndStatements.filter(column => joinAndStatements[namespace]?.and?.[column] === undefined);
|
|
2295
2303
|
if (missingRequiredWhereStatements.length)
|
|
2296
|
-
throw new
|
|
2304
|
+
throw new MissingRequiredAssociationAndClause(association, missingRequiredWhereStatements[0]);
|
|
2297
2305
|
}
|
|
2298
2306
|
applyOrderStatementForAssociation({ query, tableNameOrAlias, association, }) {
|
|
2299
2307
|
if (!query.orderBy)
|
|
@@ -2421,7 +2429,7 @@ export default class Query extends ConnectedToDB {
|
|
|
2421
2429
|
else if (val === DreamConst.passthrough) {
|
|
2422
2430
|
const column = attr.split('.').pop();
|
|
2423
2431
|
if (this.passthroughOnStatement[column] === undefined)
|
|
2424
|
-
throw new
|
|
2432
|
+
throw new MissingRequiredPassthroughForAssociationAndClause(column);
|
|
2425
2433
|
val = this.passthroughOnStatement[column];
|
|
2426
2434
|
}
|
|
2427
2435
|
if (val === null) {
|
|
@@ -2488,36 +2496,36 @@ export default class Query extends ConnectedToDB {
|
|
|
2488
2496
|
throw new CannotPassUndefinedAsAValueToAWhereClause(this.dreamClass, a2);
|
|
2489
2497
|
return { a, b, c, a2, b2, c2 };
|
|
2490
2498
|
}
|
|
2491
|
-
|
|
2492
|
-
if (!
|
|
2499
|
+
applyJoinAndStatement(join, joinAndStatement, rootTableOrAssociationAlias) {
|
|
2500
|
+
if (!joinAndStatement)
|
|
2493
2501
|
return join;
|
|
2494
|
-
join = this.
|
|
2495
|
-
join = this.
|
|
2502
|
+
join = this._applyJoinAndStatements(join, joinAndStatement.and, rootTableOrAssociationAlias);
|
|
2503
|
+
join = this._applyJoinAndStatements(join, joinAndStatement.andNot, rootTableOrAssociationAlias, {
|
|
2496
2504
|
negate: true,
|
|
2497
2505
|
});
|
|
2498
|
-
join = this.
|
|
2506
|
+
join = this._applyJoinAndAnyStatements(join, joinAndStatement.andAny, rootTableOrAssociationAlias);
|
|
2499
2507
|
return join;
|
|
2500
2508
|
}
|
|
2501
|
-
|
|
2502
|
-
if (!
|
|
2509
|
+
_applyJoinAndStatements(join, joinAndStatement, rootTableOrAssociationAlias, { negate = false, } = {}) {
|
|
2510
|
+
if (!joinAndStatement)
|
|
2503
2511
|
return join;
|
|
2504
|
-
return join.on((eb) => this.
|
|
2512
|
+
return join.on((eb) => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, {
|
|
2505
2513
|
negate,
|
|
2506
2514
|
disallowSimilarityOperator: negate,
|
|
2507
2515
|
}));
|
|
2508
2516
|
}
|
|
2509
|
-
|
|
2510
|
-
if (!
|
|
2517
|
+
_applyJoinAndAnyStatements(join, joinAndAnyStatement, rootTableOrAssociationAlias) {
|
|
2518
|
+
if (!joinAndAnyStatement)
|
|
2511
2519
|
return join;
|
|
2512
|
-
if (!
|
|
2520
|
+
if (!joinAndAnyStatement.length)
|
|
2513
2521
|
return join;
|
|
2514
2522
|
return join.on((eb) => {
|
|
2515
|
-
return eb.or(
|
|
2523
|
+
return eb.or(joinAndAnyStatement.map(joinAndStatement => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb)));
|
|
2516
2524
|
});
|
|
2517
2525
|
}
|
|
2518
|
-
|
|
2519
|
-
return this.whereStatementToExpressionWrapper(eb, Object.keys(
|
|
2520
|
-
agg[this.namespaceColumn(key.toString(), rootTableOrAssociationAlias)] =
|
|
2526
|
+
joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, { negate = false, disallowSimilarityOperator = true, } = {}) {
|
|
2527
|
+
return this.whereStatementToExpressionWrapper(eb, Object.keys(joinAndStatement).reduce((agg, key) => {
|
|
2528
|
+
agg[this.namespaceColumn(key.toString(), rootTableOrAssociationAlias)] = joinAndStatement[key];
|
|
2521
2529
|
return agg;
|
|
2522
2530
|
}, {}), {
|
|
2523
2531
|
negate,
|
|
@@ -2530,8 +2538,8 @@ export default class Query extends ConnectedToDB {
|
|
|
2530
2538
|
if (!isEmpty(query.innerJoinStatements)) {
|
|
2531
2539
|
kyselyQuery = query.recursivelyJoin({
|
|
2532
2540
|
query: kyselyQuery,
|
|
2533
|
-
|
|
2534
|
-
|
|
2541
|
+
joinStatement: query.innerJoinStatements,
|
|
2542
|
+
joinAndStatements: query.innerJoinAndStatements,
|
|
2535
2543
|
dreamClass: query.dreamClass,
|
|
2536
2544
|
previousAssociationTableOrAlias: this.baseSqlAlias,
|
|
2537
2545
|
joinType: 'inner',
|
|
@@ -2540,8 +2548,8 @@ export default class Query extends ConnectedToDB {
|
|
|
2540
2548
|
if (!isEmpty(query.leftJoinStatements)) {
|
|
2541
2549
|
kyselyQuery = query.recursivelyJoin({
|
|
2542
2550
|
query: kyselyQuery,
|
|
2543
|
-
|
|
2544
|
-
|
|
2551
|
+
joinStatement: query.leftJoinStatements,
|
|
2552
|
+
joinAndStatements: query.leftJoinAndStatements,
|
|
2545
2553
|
dreamClass: query.dreamClass,
|
|
2546
2554
|
previousAssociationTableOrAlias: this.baseSqlAlias,
|
|
2547
2555
|
joinType: 'left',
|
|
@@ -2577,11 +2585,11 @@ export default class Query extends ConnectedToDB {
|
|
|
2577
2585
|
return aliasedWhere;
|
|
2578
2586
|
}, {});
|
|
2579
2587
|
}
|
|
2580
|
-
rawifiedSelfOnClause({ associationAlias, selfAlias,
|
|
2588
|
+
rawifiedSelfOnClause({ associationAlias, selfAlias, selfAndClause, }) {
|
|
2581
2589
|
const alphanumericUnderscoreRegexp = /[^a-zA-Z0-9_]/g;
|
|
2582
2590
|
selfAlias = selfAlias.replace(alphanumericUnderscoreRegexp, '');
|
|
2583
|
-
return Object.keys(
|
|
2584
|
-
const selfColumn =
|
|
2591
|
+
return Object.keys(selfAndClause).reduce((acc, key) => {
|
|
2592
|
+
const selfColumn = selfAndClause[key]?.replace(alphanumericUnderscoreRegexp, '');
|
|
2585
2593
|
if (!selfColumn)
|
|
2586
2594
|
return acc;
|
|
2587
2595
|
acc[this.namespaceColumn(key, associationAlias)] = sql.raw(`"${snakeify(selfAlias)}"."${snakeify(selfColumn)}"`);
|
|
@@ -2659,7 +2667,7 @@ export default class Query extends ConnectedToDB {
|
|
|
2659
2667
|
return new SimilarityBuilder(this.dreamInstance, {
|
|
2660
2668
|
where: [...this.whereStatements],
|
|
2661
2669
|
whereNot: [...this.whereNotStatements],
|
|
2662
|
-
|
|
2670
|
+
joinAndStatements: this.innerJoinAndStatements,
|
|
2663
2671
|
transaction: this.dreamTransaction,
|
|
2664
2672
|
connection: this.connectionOverride,
|
|
2665
2673
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import applyScopeBypassingSettingsToQuery from '../applyScopeBypassingSettingsToQuery.js';
|
|
2
|
-
export default function associationQuery(dream, txn = null, associationName, {
|
|
2
|
+
export default function associationQuery(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
3
3
|
const association = dream['associationMetadataMap']()[associationName];
|
|
4
4
|
const associationClass = association.modelCB();
|
|
5
5
|
const dreamClass = dream.constructor;
|
|
@@ -7,8 +7,8 @@ export default function associationQuery(dream, txn = null, associationName, { j
|
|
|
7
7
|
let baseSelectQuery = dreamClassOrTransaction.where({
|
|
8
8
|
[dream.primaryKey]: dream.primaryKeyValue,
|
|
9
9
|
});
|
|
10
|
-
if (
|
|
11
|
-
baseSelectQuery = baseSelectQuery.innerJoin(association.as,
|
|
10
|
+
if (joinAndStatements && (joinAndStatements.and || joinAndStatements.andNot || joinAndStatements.andAny))
|
|
11
|
+
baseSelectQuery = baseSelectQuery.innerJoin(association.as, joinAndStatements);
|
|
12
12
|
else
|
|
13
13
|
baseSelectQuery = baseSelectQuery.innerJoin(association.as);
|
|
14
14
|
let query = txn ? associationClass.txn(txn).queryInstance() : associationClass.query();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import UnexpectedUndefined from '../../../errors/UnexpectedUndefined.js';
|
|
2
2
|
import namespaceColumn from '../../../helpers/namespaceColumn.js';
|
|
3
3
|
import applyScopeBypassingSettingsToQuery from '../applyScopeBypassingSettingsToQuery.js';
|
|
4
|
-
export default function associationUpdateQuery(dream, txn = null, associationName, {
|
|
4
|
+
export default function associationUpdateQuery(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
5
5
|
const association = dream['associationMetadataMap']()[associationName];
|
|
6
6
|
if (association === undefined)
|
|
7
7
|
throw new UnexpectedUndefined();
|
|
@@ -17,8 +17,8 @@ export default function associationUpdateQuery(dream, txn = null, associationNam
|
|
|
17
17
|
bypassAllDefaultScopes,
|
|
18
18
|
defaultScopesToBypass,
|
|
19
19
|
});
|
|
20
|
-
if (
|
|
21
|
-
nestedScope = nestedScope.innerJoin(association.as,
|
|
20
|
+
if (joinAndStatements && (joinAndStatements.and || joinAndStatements.andNot || joinAndStatements.andAny))
|
|
21
|
+
nestedScope = nestedScope.innerJoin(association.as, joinAndStatements);
|
|
22
22
|
else
|
|
23
23
|
nestedScope = nestedScope.innerJoin(association.as);
|
|
24
24
|
const nestedSelect = nestedScope
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import associationUpdateQuery from './associationUpdateQuery.js';
|
|
2
|
-
export default async function destroyAssociation(dream, txn = null, associationName, {
|
|
2
|
+
export default async function destroyAssociation(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, cascade, reallyDestroy, skipHooks, }) {
|
|
3
3
|
const query = associationUpdateQuery(dream, txn, associationName, {
|
|
4
|
-
|
|
4
|
+
joinAndStatements,
|
|
5
5
|
bypassAllDefaultScopes,
|
|
6
6
|
defaultScopesToBypass,
|
|
7
7
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import associationUpdateQuery from './associationUpdateQuery.js';
|
|
2
|
-
export default async function undestroyAssociation(dream, txn = null, associationName, {
|
|
2
|
+
export default async function undestroyAssociation(dream, txn = null, associationName, { joinAndStatements, bypassAllDefaultScopes, defaultScopesToBypass, cascade, skipHooks, }) {
|
|
3
3
|
const query = associationUpdateQuery(dream, txn, associationName, {
|
|
4
|
-
|
|
4
|
+
joinAndStatements,
|
|
5
5
|
bypassAllDefaultScopes,
|
|
6
6
|
defaultScopesToBypass,
|
|
7
7
|
});
|
|
@@ -11,12 +11,12 @@ import similarityWhereSql from './similarityWhereSql.js';
|
|
|
11
11
|
export default class SimilarityBuilder extends ConnectedToDB {
|
|
12
12
|
whereStatement;
|
|
13
13
|
whereNotStatement;
|
|
14
|
-
|
|
14
|
+
joinAndStatements = Object.freeze({});
|
|
15
15
|
constructor(dreamInstance, opts = {}) {
|
|
16
16
|
super(dreamInstance, opts);
|
|
17
17
|
this.whereStatement = Object.freeze(opts.where || []);
|
|
18
18
|
this.whereNotStatement = Object.freeze(opts.whereNot || []);
|
|
19
|
-
this.
|
|
19
|
+
this.joinAndStatements = Object.freeze(opts.joinAndStatements || {});
|
|
20
20
|
}
|
|
21
21
|
/*
|
|
22
22
|
#select
|
|
@@ -70,11 +70,11 @@ export default class SimilarityBuilder extends ConnectedToDB {
|
|
|
70
70
|
bypassOrder,
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
|
-
this.
|
|
73
|
+
this.joinAndStatementsWithSimilarityClauses().forEach((similarityStatement, index) => {
|
|
74
74
|
kyselyQuery = this.addStatementToSelectQuery({
|
|
75
75
|
kyselyQuery,
|
|
76
76
|
similarityStatement,
|
|
77
|
-
statementType: '
|
|
77
|
+
statementType: 'join_and',
|
|
78
78
|
index,
|
|
79
79
|
bypassOrder,
|
|
80
80
|
});
|
|
@@ -145,11 +145,11 @@ export default class SimilarityBuilder extends ConnectedToDB {
|
|
|
145
145
|
index,
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
|
-
this.
|
|
148
|
+
this.joinAndStatementsWithSimilarityClauses().forEach((similarityStatement, index) => {
|
|
149
149
|
kyselyQuery = this.addStatementToUpdateQuery({
|
|
150
150
|
kyselyQuery,
|
|
151
151
|
similarityStatement,
|
|
152
|
-
statementType: '
|
|
152
|
+
statementType: 'join_and',
|
|
153
153
|
index,
|
|
154
154
|
});
|
|
155
155
|
});
|
|
@@ -164,8 +164,8 @@ export default class SimilarityBuilder extends ConnectedToDB {
|
|
|
164
164
|
whereNotStatementsWithSimilarityClauses() {
|
|
165
165
|
return this.similarityStatementFilter(this.whereNotStatement);
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
return this.recursiveJoinsOnFinder(
|
|
167
|
+
joinAndStatementsWithSimilarityClauses() {
|
|
168
|
+
return this.recursiveJoinsOnFinder(removeJoinAndFromObjectHierarchy(this.joinAndStatements), this.dreamClass);
|
|
169
169
|
}
|
|
170
170
|
recursiveJoinsOnFinder(obj, dreamClass) {
|
|
171
171
|
const similar = [];
|
|
@@ -207,7 +207,7 @@ export default class SimilarityBuilder extends ConnectedToDB {
|
|
|
207
207
|
return [
|
|
208
208
|
...this.whereStatementsWithSimilarityClauses(),
|
|
209
209
|
...this.whereNotStatementsWithSimilarityClauses(),
|
|
210
|
-
...this.
|
|
210
|
+
...this.joinAndStatementsWithSimilarityClauses(),
|
|
211
211
|
];
|
|
212
212
|
}
|
|
213
213
|
addStatementToSelectQuery({ kyselyQuery, similarityStatement, index, statementType, bypassOrder, }) {
|
|
@@ -308,15 +308,15 @@ export default class SimilarityBuilder extends ConnectedToDB {
|
|
|
308
308
|
return `${statementType}_rank_${statementIndex + 1}`;
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
export const SIMILARITY_TYPES = ['where', '
|
|
312
|
-
function
|
|
311
|
+
export const SIMILARITY_TYPES = ['where', 'join_and'];
|
|
312
|
+
function removeJoinAndFromObjectHierarchy(obj) {
|
|
313
313
|
if (obj?.isOpsStatement)
|
|
314
314
|
return obj;
|
|
315
315
|
const result = {};
|
|
316
316
|
for (const key in obj) {
|
|
317
317
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
318
318
|
if (isObject(obj[key])) {
|
|
319
|
-
result[key] =
|
|
319
|
+
result[key] = removeJoinAndFromObjectHierarchy(obj[key].and || obj[key]);
|
|
320
320
|
}
|
|
321
321
|
else {
|
|
322
322
|
result[key] = obj[key];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class CannotDefineAssociationWithBothDependentAndRequiredAndClause extends Error {
|
|
2
2
|
dreamClass;
|
|
3
3
|
associationName;
|
|
4
4
|
constructor(dreamClass, associationName) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class MissingRequiredAssociationAndClause extends Error {
|
|
2
2
|
association;
|
|
3
3
|
column;
|
|
4
4
|
constructor(association, column) {
|
|
@@ -8,9 +8,9 @@ export default class MissingRequiredAssociationOnClause extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
|
-
Missing required association
|
|
11
|
+
Missing required association and-clause:
|
|
12
12
|
Association: ${this.association.as}
|
|
13
|
-
Missing
|
|
13
|
+
Missing and-clause for column: ${this.column}
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class MissingRequiredPassthroughForAssociationAndClause extends Error {
|
|
2
|
+
column;
|
|
3
|
+
constructor(column) {
|
|
4
|
+
super();
|
|
5
|
+
this.column = column;
|
|
6
|
+
}
|
|
7
|
+
get message() {
|
|
8
|
+
return `
|
|
9
|
+
Missing passthrough for association and-clause:
|
|
10
|
+
Missing passthrough and-clause for column: ${this.column}
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
}
|