@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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class MissingRequiredPassthroughForAssociationAndClause extends Error {
|
|
4
|
+
column;
|
|
5
|
+
constructor(column) {
|
|
6
|
+
super();
|
|
7
|
+
this.column = column;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
return `
|
|
11
|
+
Missing passthrough for association and-clause:
|
|
12
|
+
Missing passthrough and-clause for column: ${this.column}
|
|
13
|
+
`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = MissingRequiredPassthroughForAssociationAndClause;
|
|
@@ -259,7 +259,7 @@ may need to update the table getter in the corresponding Dream.
|
|
|
259
259
|
throw new FailedToIdentifyAssociation_js_1.default(model, associationMetaData.type, associationName, associationMetaData.globalAssociationNameOrNames);
|
|
260
260
|
const optional = associationMetaData.type === 'BelongsTo' ? associationMetaData.optional === true : null;
|
|
261
261
|
const where = associationMetaData.type === 'HasMany' || associationMetaData.type === 'HasOne'
|
|
262
|
-
? associationMetaData.
|
|
262
|
+
? associationMetaData.and || null
|
|
263
263
|
: null;
|
|
264
264
|
// NOTE
|
|
265
265
|
// this try-catch is here because the SchemaBuilder currently needs to be run twice to generate foreignKey
|
package/dist/esm/src/Dream.js
CHANGED
|
@@ -2553,7 +2553,9 @@ export default class Dream {
|
|
|
2553
2553
|
*
|
|
2554
2554
|
* @param associationName - The name of the association to destroy
|
|
2555
2555
|
* @param options - Options for destroying the association
|
|
2556
|
-
* @param options.
|
|
2556
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
2557
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
2558
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
2557
2559
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2558
2560
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2559
2561
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -2565,10 +2567,10 @@ export default class Dream {
|
|
|
2565
2567
|
throw new CannotDestroyAssociationOnUnpersistedDream(this, associationName);
|
|
2566
2568
|
return await destroyAssociation(this, null, associationName, {
|
|
2567
2569
|
...destroyOptions(options),
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2570
|
+
joinAndStatements: {
|
|
2571
|
+
and: options?.and,
|
|
2572
|
+
andNot: options?.andNot,
|
|
2573
|
+
andAny: options?.andAny,
|
|
2572
2574
|
},
|
|
2573
2575
|
});
|
|
2574
2576
|
}
|
|
@@ -2587,7 +2589,9 @@ export default class Dream {
|
|
|
2587
2589
|
*
|
|
2588
2590
|
* @param associationName - The name of the association to destroy
|
|
2589
2591
|
* @param options - Options for destroying the association
|
|
2590
|
-
* @param options.
|
|
2592
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
2593
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
2594
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
2591
2595
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2592
2596
|
* @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
|
|
2593
2597
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -2599,10 +2603,10 @@ export default class Dream {
|
|
|
2599
2603
|
throw new CannotDestroyAssociationOnUnpersistedDream(this, associationName);
|
|
2600
2604
|
return await destroyAssociation(this, null, associationName, {
|
|
2601
2605
|
...reallyDestroyOptions(options),
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
+
joinAndStatements: {
|
|
2607
|
+
and: options?.and,
|
|
2608
|
+
andNot: options?.andNot,
|
|
2609
|
+
andAny: options?.andAny,
|
|
2606
2610
|
},
|
|
2607
2611
|
});
|
|
2608
2612
|
}
|
|
@@ -2618,7 +2622,9 @@ export default class Dream {
|
|
|
2618
2622
|
*
|
|
2619
2623
|
* @param associationName - The name of the association to undestroy
|
|
2620
2624
|
* @param options - Options for undestroying the association
|
|
2621
|
-
* @param options.
|
|
2625
|
+
* @param options.and - Optional and statement to apply to query before undestroying
|
|
2626
|
+
* @param options.andNot - Optional andNot statement to apply to query before undestroying
|
|
2627
|
+
* @param options.andAny - Optional andAny statement to apply to query before undestroying
|
|
2622
2628
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
2623
2629
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2624
2630
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
|
|
@@ -2628,10 +2634,10 @@ export default class Dream {
|
|
|
2628
2634
|
async undestroyAssociation(associationName, options) {
|
|
2629
2635
|
return await undestroyAssociation(this, null, associationName, {
|
|
2630
2636
|
...undestroyOptions(options),
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2637
|
+
joinAndStatements: {
|
|
2638
|
+
and: options?.and,
|
|
2639
|
+
andNot: options?.andNot,
|
|
2640
|
+
andAny: options?.andAny,
|
|
2635
2641
|
},
|
|
2636
2642
|
});
|
|
2637
2643
|
}
|
|
@@ -2647,11 +2653,11 @@ export default class Dream {
|
|
|
2647
2653
|
* @returns A Query scoped to the specified association on the current instance
|
|
2648
2654
|
*
|
|
2649
2655
|
*/
|
|
2650
|
-
associationQuery(associationName,
|
|
2656
|
+
associationQuery(associationName, joinAndStatements) {
|
|
2651
2657
|
if (this.isNewRecord)
|
|
2652
2658
|
throw new CannotAssociationQueryOnUnpersistedDream(this, associationName);
|
|
2653
2659
|
return associationQuery(this, null, associationName, {
|
|
2654
|
-
|
|
2660
|
+
joinAndStatements: joinAndStatements,
|
|
2655
2661
|
bypassAllDefaultScopes: DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
2656
2662
|
defaultScopesToBypass: DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
2657
2663
|
});
|
|
@@ -2665,14 +2671,14 @@ export default class Dream {
|
|
|
2665
2671
|
* ```ts
|
|
2666
2672
|
* await user.createAssociation('posts', { body: 'hello world' })
|
|
2667
2673
|
* await user.createAssociation('posts', { body: 'howyadoin' })
|
|
2668
|
-
* await user.updateAssociation('posts', { body: 'goodbye world' }, {
|
|
2674
|
+
* await user.updateAssociation('posts', { body: 'goodbye world' }, { and: { body: 'hello world' }})
|
|
2669
2675
|
* // 1
|
|
2670
2676
|
* ```
|
|
2671
2677
|
*
|
|
2672
2678
|
* @param associationName - The name of the association to update
|
|
2673
2679
|
* @param attributes - The attributes to update on the association
|
|
2674
2680
|
* @param options - Options for updating the association
|
|
2675
|
-
* @param options.
|
|
2681
|
+
* @param options.and - Optional on statement to apply to query before updating
|
|
2676
2682
|
* @param options.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
|
|
2677
2683
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when updating the association. Defaults to false
|
|
2678
2684
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
|
|
@@ -2682,10 +2688,10 @@ export default class Dream {
|
|
|
2682
2688
|
if (this.isNewRecord)
|
|
2683
2689
|
throw new CannotUpdateAssociationOnUnpersistedDream(this, associationName);
|
|
2684
2690
|
return associationUpdateQuery(this, null, associationName, {
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2691
|
+
joinAndStatements: {
|
|
2692
|
+
and: updateAssociationOptions?.and,
|
|
2693
|
+
andNot: updateAssociationOptions?.andNot,
|
|
2694
|
+
andAny: updateAssociationOptions?.andAny,
|
|
2689
2695
|
},
|
|
2690
2696
|
bypassAllDefaultScopes: updateAssociationOptions?.bypassAllDefaultScopes ?? DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
2691
2697
|
defaultScopesToBypass: updateAssociationOptions?.defaultScopesToBypass ?? DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
@@ -21,21 +21,21 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
21
21
|
* @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
|
|
22
22
|
* @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.
|
|
23
23
|
* @param opts.foreignKey - A custom column name to use for the foreign key.
|
|
24
|
-
* @param opts.
|
|
25
|
-
* @param opts.
|
|
26
|
-
* @param opts.
|
|
24
|
+
* @param opts.and - An and-clause to be applied when this association is loaded
|
|
25
|
+
* @param opts.andNot - A not and-clause to be applied when this association is loaded
|
|
26
|
+
* @param opts.andAny - An andAny clause to be applied when this association is loaded
|
|
27
27
|
* @param opts.order - A custom order statement to apply to this association.
|
|
28
28
|
* @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
|
|
29
29
|
* @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.
|
|
30
30
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
31
|
-
* @param opts.
|
|
32
|
-
* @param opts.
|
|
31
|
+
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
32
|
+
* @param opts.selfAndNot - Adds a not and-clause to an association between a column on the associated model and a column on this model.
|
|
33
33
|
* @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
|
|
34
34
|
* @param opts.through - If passed, this association will travel through another association.
|
|
35
35
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
36
36
|
*/
|
|
37
37
|
export default function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
38
|
-
const { dependent, distinct, foreignKey,
|
|
38
|
+
const { dependent, distinct, foreignKey, and, andNot, andAny, order, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
39
39
|
return function (_, context) {
|
|
40
40
|
const key = context.name;
|
|
41
41
|
context.addInitializer(function () {
|
|
@@ -57,21 +57,21 @@ export default function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
|
57
57
|
dreamClass,
|
|
58
58
|
dependent: dependent ?? null,
|
|
59
59
|
methodName: key,
|
|
60
|
-
|
|
60
|
+
and: and ?? null,
|
|
61
61
|
});
|
|
62
62
|
const partialAssociation = associationPrimaryKeyAccessors({
|
|
63
63
|
modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
|
|
64
64
|
as: key,
|
|
65
65
|
dependent,
|
|
66
66
|
globalAssociationNameOrNames,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
and,
|
|
68
|
+
andNot,
|
|
69
|
+
andAny,
|
|
70
70
|
polymorphic,
|
|
71
71
|
preloadThroughColumns,
|
|
72
72
|
primaryKeyOverride,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
selfAnd,
|
|
74
|
+
selfAndNot,
|
|
75
75
|
source: source || key,
|
|
76
76
|
type: 'HasMany',
|
|
77
77
|
withoutDefaultScopes,
|
|
@@ -20,20 +20,20 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
20
20
|
*
|
|
21
21
|
* @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
|
|
22
22
|
* @param opts.foreignKey - A custom column name to use for the foreign key.
|
|
23
|
-
* @param opts.
|
|
24
|
-
* @param opts.
|
|
25
|
-
* @param opts.
|
|
23
|
+
* @param opts.and - An and-clause to be applied when this association is loaded
|
|
24
|
+
* @param opts.andNot - A not and-clause to be applied when this association is loaded
|
|
25
|
+
* @param opts.andAny - An andAny clause to be applied when this association is loaded
|
|
26
26
|
* @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
|
|
27
27
|
* @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.
|
|
28
28
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
29
|
-
* @param opts.
|
|
30
|
-
* @param opts.
|
|
29
|
+
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
30
|
+
* @param opts.selfAndNot - Adds a not and-clause to an association between a column on the associated model and a column on this model.
|
|
31
31
|
* @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
|
|
32
32
|
* @param opts.through - If passed, this association will travel through another association.
|
|
33
33
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
34
34
|
*/
|
|
35
35
|
export default function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
36
|
-
const { dependent, foreignKey,
|
|
36
|
+
const { dependent, foreignKey, and, andNot, andAny, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
37
37
|
return function (_, context) {
|
|
38
38
|
const key = context.name;
|
|
39
39
|
context.addInitializer(function () {
|
|
@@ -55,21 +55,21 @@ export default function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
|
55
55
|
dreamClass,
|
|
56
56
|
dependent: dependent ?? null,
|
|
57
57
|
methodName: key,
|
|
58
|
-
|
|
58
|
+
and: and ?? null,
|
|
59
59
|
});
|
|
60
60
|
const partialAssociation = associationPrimaryKeyAccessors({
|
|
61
61
|
modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
|
|
62
62
|
as: key,
|
|
63
63
|
dependent,
|
|
64
64
|
globalAssociationNameOrNames,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
and,
|
|
66
|
+
andNot,
|
|
67
|
+
andAny,
|
|
68
68
|
polymorphic,
|
|
69
69
|
preloadThroughColumns,
|
|
70
70
|
primaryKeyOverride,
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
selfAnd,
|
|
72
|
+
selfAndNot,
|
|
73
73
|
source: source || key,
|
|
74
74
|
through,
|
|
75
75
|
type: 'HasOne',
|
|
@@ -3,7 +3,7 @@ import { DreamConst } from '../../../dream/constants.js';
|
|
|
3
3
|
import { checkForeignKey } from '../../../errors/associations/InvalidComputedForeignKey.js';
|
|
4
4
|
import NonLoadedAssociation from '../../../errors/associations/NonLoadedAssociation.js';
|
|
5
5
|
import CannotDefineAssociationWithBothDependentAndPassthrough from '../../../errors/CannotDefineAssociationWithBothDependentAndPassthrough.js';
|
|
6
|
-
import
|
|
6
|
+
import CannotDefineAssociationWithBothDependentAndRequiredAndClause from '../../../errors/CannotDefineAssociationWithBothDependentAndRequiredAndClause.js';
|
|
7
7
|
import camelize from '../../../helpers/camelize.js';
|
|
8
8
|
import freezeBaseClassArrayMap from '../../helpers/freezeBaseClassArrayMap.js';
|
|
9
9
|
import associationToGetterSetterProp from './associationToGetterSetterProp.js';
|
|
@@ -113,11 +113,11 @@ association: ${this.as}
|
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
export function validateHasStatementArgs({ dreamClass, dependent, methodName,
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
if (dependent &&
|
|
116
|
+
export function validateHasStatementArgs({ dreamClass, dependent, methodName, and, }) {
|
|
117
|
+
const hasPassthroughAnd = Object.values(and || {}).find(val => val === DreamConst.passthrough);
|
|
118
|
+
const hasRequiredAnd = Object.values(and || {}).find(val => val === DreamConst.required);
|
|
119
|
+
if (dependent && hasPassthroughAnd)
|
|
120
120
|
throw new CannotDefineAssociationWithBothDependentAndPassthrough(dreamClass, methodName);
|
|
121
|
-
if (dependent &&
|
|
122
|
-
throw new
|
|
121
|
+
if (dependent && hasRequiredAnd)
|
|
122
|
+
throw new CannotDefineAssociationWithBothDependentAndRequiredAndClause(dreamClass, methodName);
|
|
123
123
|
}
|
|
@@ -311,11 +311,11 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
311
311
|
*
|
|
312
312
|
* @returns A Query scoped to the specified association on the current instance
|
|
313
313
|
*/
|
|
314
|
-
associationQuery(associationName,
|
|
314
|
+
associationQuery(associationName, joinAndStatements) {
|
|
315
315
|
if (this.dreamInstance.isNewRecord)
|
|
316
316
|
throw new CannotAssociationQueryOnUnpersistedDream(this.dreamInstance, associationName);
|
|
317
317
|
return associationQuery(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
318
|
-
|
|
318
|
+
joinAndStatements: joinAndStatements,
|
|
319
319
|
bypassAllDefaultScopes: DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
320
320
|
defaultScopesToBypass: DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
321
321
|
});
|
|
@@ -330,7 +330,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
330
330
|
* await ApplicationModel.transaction(async txn => {
|
|
331
331
|
* await user.txn(txn).createAssociation('posts', { body: 'hello world' })
|
|
332
332
|
* await user.txn(txn).createAssociation('posts', { body: 'howyadoin' })
|
|
333
|
-
* await user.txn(txn).updateAssociation('posts', { body: 'goodbye world' }, {
|
|
333
|
+
* await user.txn(txn).updateAssociation('posts', { body: 'goodbye world' }, { and: { body: 'hello world' }})
|
|
334
334
|
* // 1
|
|
335
335
|
* })
|
|
336
336
|
* ```
|
|
@@ -348,10 +348,10 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
348
348
|
if (this.dreamInstance.isNewRecord)
|
|
349
349
|
throw new CannotUpdateAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
350
350
|
return await associationUpdateQuery(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
351
|
+
joinAndStatements: {
|
|
352
|
+
and: updateAssociationOptions?.and,
|
|
353
|
+
andNot: updateAssociationOptions?.andNot,
|
|
354
|
+
andAny: updateAssociationOptions?.andAny,
|
|
355
355
|
},
|
|
356
356
|
bypassAllDefaultScopes: updateAssociationOptions?.bypassAllDefaultScopes ?? DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
357
357
|
defaultScopesToBypass: updateAssociationOptions?.defaultScopesToBypass ?? DEFAULT_DEFAULT_SCOPES_TO_BYPASS,
|
|
@@ -383,13 +383,15 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
383
383
|
*
|
|
384
384
|
* ```ts
|
|
385
385
|
* await ApplicationModel.transaction(async txn => {
|
|
386
|
-
* await user.txn(txn).destroyAssociation('posts', {
|
|
386
|
+
* await user.txn(txn).destroyAssociation('posts', { and: { body: 'hello world' } })
|
|
387
387
|
* })
|
|
388
388
|
* ```
|
|
389
389
|
*
|
|
390
390
|
* @param associationName - The name of the association to destroy
|
|
391
391
|
* @param options - Options for destroying the association
|
|
392
|
-
* @param options.
|
|
392
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
393
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
394
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
393
395
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
394
396
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
395
397
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -401,10 +403,10 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
401
403
|
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
402
404
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
403
405
|
...destroyOptions(options),
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
406
|
+
joinAndStatements: {
|
|
407
|
+
and: options?.and,
|
|
408
|
+
andNot: options?.andNot,
|
|
409
|
+
andAny: options?.andAny,
|
|
408
410
|
},
|
|
409
411
|
});
|
|
410
412
|
}
|
|
@@ -419,13 +421,15 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
419
421
|
*
|
|
420
422
|
* ```ts
|
|
421
423
|
* await ApplicationModel.transaction(async txn => {
|
|
422
|
-
* await user.txn(txn).reallyDestroyAssociation('posts', {
|
|
424
|
+
* await user.txn(txn).reallyDestroyAssociation('posts', { and: { body: 'hello world' } })
|
|
423
425
|
* })
|
|
424
426
|
* ```
|
|
425
427
|
*
|
|
426
428
|
* @param associationName - The name of the association to destroy
|
|
427
429
|
* @param options - Options for destroying the association
|
|
428
|
-
* @param options.
|
|
430
|
+
* @param options.and - Optional and statement to apply to query before destroying
|
|
431
|
+
* @param options.andNot - Optional andNot statement to apply to query before destroying
|
|
432
|
+
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
429
433
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
430
434
|
* @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
|
|
431
435
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
|
|
@@ -437,10 +441,10 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
437
441
|
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
438
442
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
439
443
|
...reallyDestroyOptions(options),
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
joinAndStatements: {
|
|
445
|
+
and: options?.and,
|
|
446
|
+
andNot: options?.andNot,
|
|
447
|
+
andAny: options?.andAny,
|
|
444
448
|
},
|
|
445
449
|
});
|
|
446
450
|
}
|
|
@@ -451,12 +455,14 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
451
455
|
* will also be undeleted.
|
|
452
456
|
*
|
|
453
457
|
* ```ts
|
|
454
|
-
* await user.undestroyAssociation('posts', {
|
|
458
|
+
* await user.undestroyAssociation('posts', { and: { body: 'hello world' } })
|
|
455
459
|
* ```
|
|
456
460
|
*
|
|
457
461
|
* @param associationName - The name of the association to undestroy
|
|
458
462
|
* @param options - Options for undestroying the association
|
|
459
|
-
* @param options.
|
|
463
|
+
* @param options.and - Optional and statement to apply to query before undestroying
|
|
464
|
+
* @param options.andNot - Optional andNot statement to apply to query before undestroying
|
|
465
|
+
* @param options.andAny - Optional andAny statement to apply to query before undestroying
|
|
460
466
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
461
467
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
462
468
|
* @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
|
|
@@ -466,10 +472,10 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
466
472
|
async undestroyAssociation(associationName, options) {
|
|
467
473
|
return await undestroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
468
474
|
...undestroyOptions(options),
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
475
|
+
joinAndStatements: {
|
|
476
|
+
and: options?.and,
|
|
477
|
+
andNot: options?.andNot,
|
|
478
|
+
andAny: options?.andAny,
|
|
473
479
|
},
|
|
474
480
|
});
|
|
475
481
|
}
|