@rvoh/dream 0.36.3 → 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/cjs/src/serializer/index.js +6 -2
- 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/esm/src/serializer/index.js +6 -2
- 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
package/README.md
CHANGED
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -2555,7 +2555,9 @@ class Dream {
|
|
|
2555
2555
|
*
|
|
2556
2556
|
* @param associationName - The name of the association to destroy
|
|
2557
2557
|
* @param options - Options for destroying the association
|
|
2558
|
-
* @param options.
|
|
2558
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
2559
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
2560
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
2559
2561
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2560
2562
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2561
2563
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -2567,10 +2569,10 @@ class Dream {
|
|
|
2567
2569
|
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2568
2570
|
return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
|
|
2569
2571
|
...(0, destroyOptions_js_1.destroyOptions)(options),
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2572
|
+
joinAndStatements: {
|
|
2573
|
+
and: options?.and,
|
|
2574
|
+
andNot: options?.andNot,
|
|
2575
|
+
andAny: options?.andAny,
|
|
2574
2576
|
},
|
|
2575
2577
|
});
|
|
2576
2578
|
}
|
|
@@ -2589,7 +2591,9 @@ class Dream {
|
|
|
2589
2591
|
*
|
|
2590
2592
|
* @param associationName - The name of the association to destroy
|
|
2591
2593
|
* @param options - Options for destroying the association
|
|
2592
|
-
* @param options.
|
|
2594
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
2595
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
2596
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
2593
2597
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2594
2598
|
* @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
|
|
2595
2599
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -2601,10 +2605,10 @@ class Dream {
|
|
|
2601
2605
|
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2602
2606
|
return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
|
|
2603
2607
|
...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
+
joinAndStatements: {
|
|
2609
|
+
and: options?.and,
|
|
2610
|
+
andNot: options?.andNot,
|
|
2611
|
+
andAny: options?.andAny,
|
|
2608
2612
|
},
|
|
2609
2613
|
});
|
|
2610
2614
|
}
|
|
@@ -2620,7 +2624,9 @@ class Dream {
|
|
|
2620
2624
|
*
|
|
2621
2625
|
* @param associationName - The name of the association to undestroy
|
|
2622
2626
|
* @param options - Options for undestroying the association
|
|
2623
|
-
* @param options.
|
|
2627
|
+
* @param options.and - Optional and statement to apply to query before undestroying
|
|
2628
|
+
* @param options.andNot - Optional andNot statement to apply to query before undestroying
|
|
2629
|
+
* @param options.andAny - Optional andAny statement to apply to query before undestroying
|
|
2624
2630
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
2625
2631
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2626
2632
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
|
|
@@ -2630,10 +2636,10 @@ class Dream {
|
|
|
2630
2636
|
async undestroyAssociation(associationName, options) {
|
|
2631
2637
|
return await (0, undestroyAssociation_js_1.default)(this, null, associationName, {
|
|
2632
2638
|
...(0, destroyOptions_js_1.undestroyOptions)(options),
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2639
|
+
joinAndStatements: {
|
|
2640
|
+
and: options?.and,
|
|
2641
|
+
andNot: options?.andNot,
|
|
2642
|
+
andAny: options?.andAny,
|
|
2637
2643
|
},
|
|
2638
2644
|
});
|
|
2639
2645
|
}
|
|
@@ -2649,11 +2655,11 @@ class Dream {
|
|
|
2649
2655
|
* @returns A Query scoped to the specified association on the current instance
|
|
2650
2656
|
*
|
|
2651
2657
|
*/
|
|
2652
|
-
associationQuery(associationName,
|
|
2658
|
+
associationQuery(associationName, joinAndStatements) {
|
|
2653
2659
|
if (this.isNewRecord)
|
|
2654
2660
|
throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this, associationName);
|
|
2655
2661
|
return (0, associationQuery_js_1.default)(this, null, associationName, {
|
|
2656
|
-
|
|
2662
|
+
joinAndStatements: joinAndStatements,
|
|
2657
2663
|
bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
2658
2664
|
defaultScopesToBypass: scopeHelpers_js_1.DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
2659
2665
|
});
|
|
@@ -2667,14 +2673,14 @@ class Dream {
|
|
|
2667
2673
|
* ```ts
|
|
2668
2674
|
* await user.createAssociation('posts', { body: 'hello world' })
|
|
2669
2675
|
* await user.createAssociation('posts', { body: 'howyadoin' })
|
|
2670
|
-
* await user.updateAssociation('posts', { body: 'goodbye world' }, {
|
|
2676
|
+
* await user.updateAssociation('posts', { body: 'goodbye world' }, { and: { body: 'hello world' }})
|
|
2671
2677
|
* // 1
|
|
2672
2678
|
* ```
|
|
2673
2679
|
*
|
|
2674
2680
|
* @param associationName - The name of the association to update
|
|
2675
2681
|
* @param attributes - The attributes to update on the association
|
|
2676
2682
|
* @param options - Options for updating the association
|
|
2677
|
-
* @param options.
|
|
2683
|
+
* @param options.and - Optional on statement to apply to query before updating
|
|
2678
2684
|
* @param options.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
|
|
2679
2685
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when updating the association. Defaults to false
|
|
2680
2686
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
|
|
@@ -2684,10 +2690,10 @@ class Dream {
|
|
|
2684
2690
|
if (this.isNewRecord)
|
|
2685
2691
|
throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2686
2692
|
return (0, associationUpdateQuery_js_1.default)(this, null, associationName, {
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2693
|
+
joinAndStatements: {
|
|
2694
|
+
and: updateAssociationOptions?.and,
|
|
2695
|
+
andNot: updateAssociationOptions?.andNot,
|
|
2696
|
+
andAny: updateAssociationOptions?.andAny,
|
|
2691
2697
|
},
|
|
2692
2698
|
bypassAllDefaultScopes: updateAssociationOptions?.bypassAllDefaultScopes ?? scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
2693
2699
|
defaultScopesToBypass: updateAssociationOptions?.defaultScopesToBypass ?? scopeHelpers_js_1.DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
@@ -24,21 +24,21 @@ const shared_js_1 = require("./shared.js");
|
|
|
24
24
|
* @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
|
|
25
25
|
* @param opts.distinct - Can be a column name, or else a boolean. If a column name, a distinct clause will be applied to the column. If true, a distinct clause will be applied to the primary key.
|
|
26
26
|
* @param opts.foreignKey - A custom column name to use for the foreign key.
|
|
27
|
-
* @param opts.
|
|
28
|
-
* @param opts.
|
|
29
|
-
* @param opts.
|
|
27
|
+
* @param opts.and - An and-clause to be applied when this association is loaded
|
|
28
|
+
* @param opts.andNot - A not and-clause to be applied when this association is loaded
|
|
29
|
+
* @param opts.andAny - An andAny clause to be applied when this association is loaded
|
|
30
30
|
* @param opts.order - A custom order statement to apply to this association.
|
|
31
31
|
* @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
|
|
32
32
|
* @param opts.preloadThroughColumns - An array of columns to pluck off the through association attached to this association. Can only be set if `through` is also set.
|
|
33
33
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
34
|
-
* @param opts.
|
|
35
|
-
* @param opts.
|
|
34
|
+
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
35
|
+
* @param opts.selfAndNot - Adds a not and-clause to an association between a column on the associated model and a column on this model.
|
|
36
36
|
* @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
|
|
37
37
|
* @param opts.through - If passed, this association will travel through another association.
|
|
38
38
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
39
39
|
*/
|
|
40
40
|
function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
41
|
-
const { dependent, distinct, foreignKey,
|
|
41
|
+
const { dependent, distinct, foreignKey, and, andNot, andAny, order, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
42
42
|
return function (_, context) {
|
|
43
43
|
const key = context.name;
|
|
44
44
|
context.addInitializer(function () {
|
|
@@ -60,21 +60,21 @@ function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
|
60
60
|
dreamClass,
|
|
61
61
|
dependent: dependent ?? null,
|
|
62
62
|
methodName: key,
|
|
63
|
-
|
|
63
|
+
and: and ?? null,
|
|
64
64
|
});
|
|
65
65
|
const partialAssociation = (0, shared_js_1.associationPrimaryKeyAccessors)({
|
|
66
66
|
modelCB: () => (0, lookupModelByGlobalNameOrNames_js_1.default)(globalAssociationNameOrNames),
|
|
67
67
|
as: key,
|
|
68
68
|
dependent,
|
|
69
69
|
globalAssociationNameOrNames,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
and,
|
|
71
|
+
andNot,
|
|
72
|
+
andAny,
|
|
73
73
|
polymorphic,
|
|
74
74
|
preloadThroughColumns,
|
|
75
75
|
primaryKeyOverride,
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
selfAnd,
|
|
77
|
+
selfAndNot,
|
|
78
78
|
source: source || key,
|
|
79
79
|
type: 'HasMany',
|
|
80
80
|
withoutDefaultScopes,
|
|
@@ -23,20 +23,20 @@ const shared_js_1 = require("./shared.js");
|
|
|
23
23
|
*
|
|
24
24
|
* @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
|
|
25
25
|
* @param opts.foreignKey - A custom column name to use for the foreign key.
|
|
26
|
-
* @param opts.
|
|
27
|
-
* @param opts.
|
|
28
|
-
* @param opts.
|
|
26
|
+
* @param opts.and - An and-clause to be applied when this association is loaded
|
|
27
|
+
* @param opts.andNot - A not and-clause to be applied when this association is loaded
|
|
28
|
+
* @param opts.andAny - An andAny clause to be applied when this association is loaded
|
|
29
29
|
* @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
|
|
30
30
|
* @param opts.preloadThroughColumns - An array of columns to pluck off the through association attached to this association. Can only be set if `through` is also set.
|
|
31
31
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
32
|
-
* @param opts.
|
|
33
|
-
* @param opts.
|
|
32
|
+
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
33
|
+
* @param opts.selfAndNot - Adds a not and-clause to an association between a column on the associated model and a column on this model.
|
|
34
34
|
* @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
|
|
35
35
|
* @param opts.through - If passed, this association will travel through another association.
|
|
36
36
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
37
37
|
*/
|
|
38
38
|
function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
39
|
-
const { dependent, foreignKey,
|
|
39
|
+
const { dependent, foreignKey, and, andNot, andAny, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
40
40
|
return function (_, context) {
|
|
41
41
|
const key = context.name;
|
|
42
42
|
context.addInitializer(function () {
|
|
@@ -58,21 +58,21 @@ function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
|
58
58
|
dreamClass,
|
|
59
59
|
dependent: dependent ?? null,
|
|
60
60
|
methodName: key,
|
|
61
|
-
|
|
61
|
+
and: and ?? null,
|
|
62
62
|
});
|
|
63
63
|
const partialAssociation = (0, shared_js_1.associationPrimaryKeyAccessors)({
|
|
64
64
|
modelCB: () => (0, lookupModelByGlobalNameOrNames_js_1.default)(globalAssociationNameOrNames),
|
|
65
65
|
as: key,
|
|
66
66
|
dependent,
|
|
67
67
|
globalAssociationNameOrNames,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
and,
|
|
69
|
+
andNot,
|
|
70
|
+
andAny,
|
|
71
71
|
polymorphic,
|
|
72
72
|
preloadThroughColumns,
|
|
73
73
|
primaryKeyOverride,
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
selfAnd,
|
|
75
|
+
selfAndNot,
|
|
76
76
|
source: source || key,
|
|
77
77
|
through,
|
|
78
78
|
type: 'HasOne',
|
|
@@ -12,7 +12,7 @@ const constants_js_1 = require("../../../dream/constants.js");
|
|
|
12
12
|
const InvalidComputedForeignKey_js_1 = require("../../../errors/associations/InvalidComputedForeignKey.js");
|
|
13
13
|
const NonLoadedAssociation_js_1 = require("../../../errors/associations/NonLoadedAssociation.js");
|
|
14
14
|
const CannotDefineAssociationWithBothDependentAndPassthrough_js_1 = require("../../../errors/CannotDefineAssociationWithBothDependentAndPassthrough.js");
|
|
15
|
-
const
|
|
15
|
+
const CannotDefineAssociationWithBothDependentAndRequiredAndClause_js_1 = require("../../../errors/CannotDefineAssociationWithBothDependentAndRequiredAndClause.js");
|
|
16
16
|
const camelize_js_1 = require("../../../helpers/camelize.js");
|
|
17
17
|
const freezeBaseClassArrayMap_js_1 = require("../../helpers/freezeBaseClassArrayMap.js");
|
|
18
18
|
const associationToGetterSetterProp_js_1 = require("./associationToGetterSetterProp.js");
|
|
@@ -122,11 +122,11 @@ association: ${this.as}
|
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
function validateHasStatementArgs({ dreamClass, dependent, methodName,
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
if (dependent &&
|
|
125
|
+
function validateHasStatementArgs({ dreamClass, dependent, methodName, and, }) {
|
|
126
|
+
const hasPassthroughAnd = Object.values(and || {}).find(val => val === constants_js_1.DreamConst.passthrough);
|
|
127
|
+
const hasRequiredAnd = Object.values(and || {}).find(val => val === constants_js_1.DreamConst.required);
|
|
128
|
+
if (dependent && hasPassthroughAnd)
|
|
129
129
|
throw new CannotDefineAssociationWithBothDependentAndPassthrough_js_1.default(dreamClass, methodName);
|
|
130
|
-
if (dependent &&
|
|
131
|
-
throw new
|
|
130
|
+
if (dependent && hasRequiredAnd)
|
|
131
|
+
throw new CannotDefineAssociationWithBothDependentAndRequiredAndClause_js_1.default(dreamClass, methodName);
|
|
132
132
|
}
|
|
@@ -313,11 +313,11 @@ class DreamInstanceTransactionBuilder {
|
|
|
313
313
|
*
|
|
314
314
|
* @returns A Query scoped to the specified association on the current instance
|
|
315
315
|
*/
|
|
316
|
-
associationQuery(associationName,
|
|
316
|
+
associationQuery(associationName, joinAndStatements) {
|
|
317
317
|
if (this.dreamInstance.isNewRecord)
|
|
318
318
|
throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
319
319
|
return (0, associationQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
320
|
-
|
|
320
|
+
joinAndStatements: joinAndStatements,
|
|
321
321
|
bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
322
322
|
defaultScopesToBypass: scopeHelpers_js_1.DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
323
323
|
});
|
|
@@ -332,7 +332,7 @@ class DreamInstanceTransactionBuilder {
|
|
|
332
332
|
* await ApplicationModel.transaction(async txn => {
|
|
333
333
|
* await user.txn(txn).createAssociation('posts', { body: 'hello world' })
|
|
334
334
|
* await user.txn(txn).createAssociation('posts', { body: 'howyadoin' })
|
|
335
|
-
* await user.txn(txn).updateAssociation('posts', { body: 'goodbye world' }, {
|
|
335
|
+
* await user.txn(txn).updateAssociation('posts', { body: 'goodbye world' }, { and: { body: 'hello world' }})
|
|
336
336
|
* // 1
|
|
337
337
|
* })
|
|
338
338
|
* ```
|
|
@@ -350,10 +350,10 @@ class DreamInstanceTransactionBuilder {
|
|
|
350
350
|
if (this.dreamInstance.isNewRecord)
|
|
351
351
|
throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
352
352
|
return await (0, associationUpdateQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
joinAndStatements: {
|
|
354
|
+
and: updateAssociationOptions?.and,
|
|
355
|
+
andNot: updateAssociationOptions?.andNot,
|
|
356
|
+
andAny: updateAssociationOptions?.andAny,
|
|
357
357
|
},
|
|
358
358
|
bypassAllDefaultScopes: updateAssociationOptions?.bypassAllDefaultScopes ?? scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
359
359
|
defaultScopesToBypass: updateAssociationOptions?.defaultScopesToBypass ?? scopeHelpers_js_1.DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
@@ -385,13 +385,15 @@ class DreamInstanceTransactionBuilder {
|
|
|
385
385
|
*
|
|
386
386
|
* ```ts
|
|
387
387
|
* await ApplicationModel.transaction(async txn => {
|
|
388
|
-
* await user.txn(txn).destroyAssociation('posts', {
|
|
388
|
+
* await user.txn(txn).destroyAssociation('posts', { and: { body: 'hello world' } })
|
|
389
389
|
* })
|
|
390
390
|
* ```
|
|
391
391
|
*
|
|
392
392
|
* @param associationName - The name of the association to destroy
|
|
393
393
|
* @param options - Options for destroying the association
|
|
394
|
-
* @param options.
|
|
394
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
395
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
396
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
395
397
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
396
398
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
397
399
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -403,10 +405,10 @@ class DreamInstanceTransactionBuilder {
|
|
|
403
405
|
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
404
406
|
return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
405
407
|
...(0, destroyOptions_js_1.destroyOptions)(options),
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
408
|
+
joinAndStatements: {
|
|
409
|
+
and: options?.and,
|
|
410
|
+
andNot: options?.andNot,
|
|
411
|
+
andAny: options?.andAny,
|
|
410
412
|
},
|
|
411
413
|
});
|
|
412
414
|
}
|
|
@@ -421,13 +423,15 @@ class DreamInstanceTransactionBuilder {
|
|
|
421
423
|
*
|
|
422
424
|
* ```ts
|
|
423
425
|
* await ApplicationModel.transaction(async txn => {
|
|
424
|
-
* await user.txn(txn).reallyDestroyAssociation('posts', {
|
|
426
|
+
* await user.txn(txn).reallyDestroyAssociation('posts', { and: { body: 'hello world' } })
|
|
425
427
|
* })
|
|
426
428
|
* ```
|
|
427
429
|
*
|
|
428
430
|
* @param associationName - The name of the association to destroy
|
|
429
431
|
* @param options - Options for destroying the association
|
|
430
|
-
* @param options.
|
|
432
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
433
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
434
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
431
435
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
432
436
|
* @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
|
|
433
437
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -439,10 +443,10 @@ class DreamInstanceTransactionBuilder {
|
|
|
439
443
|
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
440
444
|
return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
441
445
|
...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
+
joinAndStatements: {
|
|
447
|
+
and: options?.and,
|
|
448
|
+
andNot: options?.andNot,
|
|
449
|
+
andAny: options?.andAny,
|
|
446
450
|
},
|
|
447
451
|
});
|
|
448
452
|
}
|
|
@@ -453,12 +457,14 @@ class DreamInstanceTransactionBuilder {
|
|
|
453
457
|
* will also be undeleted.
|
|
454
458
|
*
|
|
455
459
|
* ```ts
|
|
456
|
-
* await user.undestroyAssociation('posts', {
|
|
460
|
+
* await user.undestroyAssociation('posts', { and: { body: 'hello world' } })
|
|
457
461
|
* ```
|
|
458
462
|
*
|
|
459
463
|
* @param associationName - The name of the association to undestroy
|
|
460
464
|
* @param options - Options for undestroying the association
|
|
461
|
-
* @param options.
|
|
465
|
+
* @param options.and - Optional and statement to apply to query before undestroying
|
|
466
|
+
* @param options.andNot - Optional andNot statement to apply to query before undestroying
|
|
467
|
+
* @param options.andAny - Optional andAny statement to apply to query before undestroying
|
|
462
468
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
463
469
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
464
470
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
|
|
@@ -468,10 +474,10 @@ class DreamInstanceTransactionBuilder {
|
|
|
468
474
|
async undestroyAssociation(associationName, options) {
|
|
469
475
|
return await (0, undestroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
470
476
|
...(0, destroyOptions_js_1.undestroyOptions)(options),
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
477
|
+
joinAndStatements: {
|
|
478
|
+
and: options?.and,
|
|
479
|
+
andNot: options?.andNot,
|
|
480
|
+
andAny: options?.andAny,
|
|
475
481
|
},
|
|
476
482
|
});
|
|
477
483
|
}
|