@rvoh/dream 2.28.3 → 2.30.1
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/dist/cjs/src/Dream.js +5 -3
- package/dist/cjs/src/decorators/field/sortable/helpers/setPosition.js +11 -2
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +3 -1
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/cjs/src/dream/LoadBuilder.js +4 -2
- package/dist/cjs/src/dream/Query.js +2 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +69 -32
- package/dist/cjs/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
- package/dist/cjs/src/dream/internal/associations/loadedOrLoadAssociation.js +2 -0
- package/dist/cjs/src/dream/internal/installPersistedAttribute.js +9 -0
- package/dist/cjs/src/dream/internal/instanceMutationOptions.js +1 -0
- package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +1 -1
- package/dist/cjs/src/dream/internal/reload.js +3 -1
- package/dist/cjs/src/errors/associations/IncompatibleThroughAssociationTarget.js +11 -0
- package/dist/esm/src/Dream.js +5 -3
- package/dist/esm/src/decorators/field/sortable/helpers/setPosition.js +11 -2
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +3 -1
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/esm/src/dream/LoadBuilder.js +4 -2
- package/dist/esm/src/dream/Query.js +2 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +69 -32
- package/dist/esm/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
- package/dist/esm/src/dream/internal/associations/loadedOrLoadAssociation.js +2 -0
- package/dist/esm/src/dream/internal/installPersistedAttribute.js +9 -0
- package/dist/esm/src/dream/internal/instanceMutationOptions.js +1 -0
- package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +1 -1
- package/dist/esm/src/dream/internal/reload.js +3 -1
- package/dist/esm/src/errors/associations/IncompatibleThroughAssociationTarget.js +11 -0
- package/dist/types/src/Dream.d.ts +39 -25
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +4 -2
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +15 -21
- package/dist/types/src/dream/LoadBuilder.d.ts +3 -1
- package/dist/types/src/dream/Query.d.ts +2 -0
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -1
- package/dist/types/src/dream/internal/associations/loadedOrLoadAssociation.d.ts +2 -0
- package/dist/types/src/dream/internal/installPersistedAttribute.d.ts +6 -0
- package/dist/types/src/dream/internal/instanceMutationOptions.d.ts +13 -0
- package/dist/types/src/errors/associations/IncompatibleThroughAssociationTarget.d.ts +9 -0
- package/docs/classes/db.DreamMigrationHelpers.html +11 -11
- package/docs/classes/db.KyselyQueryDriver.html +43 -43
- package/docs/classes/db.PostgresQueryDriver.html +44 -44
- package/docs/classes/db.QueryDriverBase.html +42 -42
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.SortableBatchRequiresTooManyScopeLocks.html +3 -3
- package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +150 -145
- package/docs/classes/index.DreamApp.html +10 -10
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +69 -68
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +11 -11
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +3 -3
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +5 -5
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ import DreamApp from '../../dream-app/index.js';
|
|
|
21
21
|
import Dream from '../../Dream.js';
|
|
22
22
|
import ArrayTargetIncompatibleWithThroughAssociation from '../../errors/associations/ArrayTargetIncompatibleWithThroughAssociation.js';
|
|
23
23
|
import CannotJoinPolymorphicBelongsToError from '../../errors/associations/CannotJoinPolymorphicBelongsToError.js';
|
|
24
|
+
import IncompatibleThroughAssociationTarget from '../../errors/associations/IncompatibleThroughAssociationTarget.js';
|
|
24
25
|
import JoinAttemptedOnMissingAssociation from '../../errors/associations/JoinAttemptedOnMissingAssociation.js';
|
|
25
26
|
import MissingRequiredAssociationAndClause from '../../errors/associations/MissingRequiredAssociationAndClause.js';
|
|
26
27
|
import MissingRequiredPassthroughForAssociationAndClause from '../../errors/associations/MissingRequiredPassthroughForAssociationAndClause.js';
|
|
@@ -1547,7 +1548,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
1547
1548
|
joinAndStatement,
|
|
1548
1549
|
joinType,
|
|
1549
1550
|
previousThroughAssociations: [],
|
|
1550
|
-
|
|
1551
|
+
polymorphicSourceTargetModelClass: undefined,
|
|
1551
1552
|
});
|
|
1552
1553
|
query = results.query;
|
|
1553
1554
|
/**
|
|
@@ -1976,7 +1977,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
1976
1977
|
joinAndStatement: {},
|
|
1977
1978
|
previousThroughAssociations: [],
|
|
1978
1979
|
joinType,
|
|
1979
|
-
|
|
1980
|
+
polymorphicSourceTargetModelClass: undefined,
|
|
1980
1981
|
});
|
|
1981
1982
|
}
|
|
1982
1983
|
const associatedDreamClass = associationReferencedByThroughAssociation.modelCB();
|
|
@@ -1992,12 +1993,24 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
1992
1993
|
association: throughAssociation,
|
|
1993
1994
|
throughClass: associatedDreamClass,
|
|
1994
1995
|
});
|
|
1996
|
+
const outermostThroughAssociation = previousThroughAssociations[0]?.association ?? throughAssociation;
|
|
1997
|
+
const outermostTargetModelClass = outermostThroughAssociation.modelCB();
|
|
1998
|
+
const sourceTargetModelClassOrClasses = sourceAssociation.modelCB();
|
|
1999
|
+
const sourceTargetModelClasses = Array.isArray(sourceTargetModelClassOrClasses)
|
|
2000
|
+
? sourceTargetModelClassOrClasses
|
|
2001
|
+
: [sourceTargetModelClassOrClasses];
|
|
2002
|
+
if (!sourceTargetModelClasses.some(sourceTargetModelClass => outermostTargetModelClass.typeof(sourceTargetModelClass)))
|
|
2003
|
+
throw new IncompatibleThroughAssociationTarget({
|
|
2004
|
+
outermostAssociation: outermostThroughAssociation,
|
|
2005
|
+
outermostTargetModelClass,
|
|
2006
|
+
sourceAssociation,
|
|
2007
|
+
});
|
|
1995
2008
|
/**
|
|
1996
|
-
*
|
|
1997
|
-
* association
|
|
2009
|
+
* A polymorphic source can accept several model classes. The outermost
|
|
2010
|
+
* association target selects the one this through chain is following.
|
|
1998
2011
|
*/
|
|
1999
|
-
const
|
|
2000
|
-
?
|
|
2012
|
+
const polymorphicSourceTargetModelClass = Array.isArray(sourceTargetModelClassOrClasses)
|
|
2013
|
+
? outermostTargetModelClass
|
|
2001
2014
|
: undefined;
|
|
2002
2015
|
/**
|
|
2003
2016
|
* Add the source that `sourceAssociation` points to. Note that since joinsBridgeThroughAssociations
|
|
@@ -2031,7 +2044,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2031
2044
|
{ association: throughAssociation, selfTableAlias: previousTableAlias },
|
|
2032
2045
|
],
|
|
2033
2046
|
joinType,
|
|
2034
|
-
|
|
2047
|
+
polymorphicSourceTargetModelClass,
|
|
2035
2048
|
});
|
|
2036
2049
|
}
|
|
2037
2050
|
applyOneJoin({ query, dreamClass, association,
|
|
@@ -2054,7 +2067,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2054
2067
|
/**
|
|
2055
2068
|
* previousTableAlias is always set
|
|
2056
2069
|
*/
|
|
2057
|
-
previousTableAlias, selfTableAlias = previousTableAlias, joinAndStatement = {}, previousThroughAssociations, joinType,
|
|
2070
|
+
previousTableAlias, selfTableAlias = previousTableAlias, joinAndStatement = {}, previousThroughAssociations, joinType, polymorphicSourceTargetModelClass, }) {
|
|
2058
2071
|
if (association.type !== 'BelongsTo' && association.through) {
|
|
2059
2072
|
return this.joinsBridgeThroughAssociations({
|
|
2060
2073
|
query,
|
|
@@ -2077,7 +2090,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2077
2090
|
joinAndStatement,
|
|
2078
2091
|
previousThroughAssociations,
|
|
2079
2092
|
joinType,
|
|
2080
|
-
|
|
2093
|
+
polymorphicSourceTargetModelClass,
|
|
2081
2094
|
});
|
|
2082
2095
|
}
|
|
2083
2096
|
addAssociationJoinStatementToQuery({ query, dreamClass, association,
|
|
@@ -2100,12 +2113,38 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2100
2113
|
/**
|
|
2101
2114
|
* previousTableAlias is always set
|
|
2102
2115
|
*/
|
|
2103
|
-
previousTableAlias, selfTableAlias, joinAndStatement, previousThroughAssociations, joinType,
|
|
2116
|
+
previousTableAlias, selfTableAlias, joinAndStatement, previousThroughAssociations, joinType, polymorphicSourceTargetModelClass, }) {
|
|
2104
2117
|
const currentTableAlias = explicitAlias ?? association.as;
|
|
2105
|
-
const
|
|
2106
|
-
const
|
|
2107
|
-
?
|
|
2108
|
-
:
|
|
2118
|
+
const associationModelClassOrPolymorphicModelClasses = association.modelCB();
|
|
2119
|
+
const modelClassUsedForJoinConditions = Array.isArray(associationModelClassOrPolymorphicModelClasses)
|
|
2120
|
+
? associationModelClassOrPolymorphicModelClasses[0]
|
|
2121
|
+
: associationModelClassOrPolymorphicModelClasses;
|
|
2122
|
+
/**
|
|
2123
|
+
* The outermost through association defines what callers expect this join to
|
|
2124
|
+
* return, so its target is the single owner of the target table's default
|
|
2125
|
+
* scopes. Inner associations describe how to reach that table; the
|
|
2126
|
+
* compatibility check in `joinsBridgeThroughAssociations` ensures they can
|
|
2127
|
+
* actually return the outer target.
|
|
2128
|
+
*
|
|
2129
|
+
* For example, BearBnB already defines `Host.places` and `Place.rooms`. It
|
|
2130
|
+
* could expose only bedrooms from a host without adding `Place.bedrooms`:
|
|
2131
|
+
*
|
|
2132
|
+
* // Place.ts
|
|
2133
|
+
* @deco.HasMany('Room')
|
|
2134
|
+
* public rooms: Room[]
|
|
2135
|
+
*
|
|
2136
|
+
* // Host.ts
|
|
2137
|
+
* @deco.HasMany('Room/Bedroom', { through: 'places', source: 'rooms' })
|
|
2138
|
+
* public bedrooms: Bedroom[]
|
|
2139
|
+
*
|
|
2140
|
+
* `Host.bedrooms` is the outermost association, so Bedroom's `dream:STI`
|
|
2141
|
+
* scope is applied once to the final rooms join. Bedroom is a subclass of
|
|
2142
|
+
* Room, so `Place.rooms` is a compatible path. Reversing those targets, or
|
|
2143
|
+
* mixing sibling STI children, raises instead of silently changing meaning.
|
|
2144
|
+
*/
|
|
2145
|
+
const modelClassWhoseDefaultScopesApplyToJoin = previousThroughAssociations[0]?.association.modelCB() ??
|
|
2146
|
+
polymorphicSourceTargetModelClass ??
|
|
2147
|
+
modelClassUsedForJoinConditions;
|
|
2109
2148
|
/**
|
|
2110
2149
|
* Stacked order/distinct clauses are applied in join order: the options of
|
|
2111
2150
|
* the through association whose bridging joins were added to the query
|
|
@@ -2131,22 +2170,22 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2131
2170
|
}
|
|
2132
2171
|
}
|
|
2133
2172
|
if (association.type === 'BelongsTo') {
|
|
2134
|
-
if (!
|
|
2173
|
+
if (!polymorphicSourceTargetModelClass && Array.isArray(association.modelCB()))
|
|
2135
2174
|
throw new CannotJoinPolymorphicBelongsToError({
|
|
2136
2175
|
dreamClass,
|
|
2137
2176
|
association,
|
|
2138
2177
|
innerJoinStatements: this.query['innerJoinStatements'],
|
|
2139
2178
|
leftJoinStatements: this.query['leftJoinStatements'],
|
|
2140
2179
|
});
|
|
2141
|
-
const to = (
|
|
2180
|
+
const to = (polymorphicSourceTargetModelClass ?? association.modelCB()).table;
|
|
2142
2181
|
const joinTableExpression = this.aliasedJoinTableExpression(to, currentTableAlias);
|
|
2143
2182
|
query = query[(joinType === 'inner' ? 'innerJoin' : 'leftJoin')](joinTableExpression, (join) => {
|
|
2144
2183
|
join = join.onRef(this.namespaceColumn(association.foreignKey(), previousTableAlias), '=', this.namespaceColumn(association.primaryKey(undefined, {
|
|
2145
|
-
associatedClassOverride:
|
|
2184
|
+
associatedClassOverride: polymorphicSourceTargetModelClass,
|
|
2146
2185
|
}), currentTableAlias));
|
|
2147
|
-
if (
|
|
2186
|
+
if (polymorphicSourceTargetModelClass) {
|
|
2148
2187
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement({
|
|
2149
|
-
[association.foreignKeyTypeField()]:
|
|
2188
|
+
[association.foreignKeyTypeField()]: polymorphicSourceTargetModelClass.sanitizedName,
|
|
2150
2189
|
}, previousTableAlias)));
|
|
2151
2190
|
}
|
|
2152
2191
|
join = this.applyPreviousThroughAssociationAndStatementsToJoinStatement({
|
|
@@ -2156,14 +2195,14 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2156
2195
|
currentTableAlias,
|
|
2157
2196
|
joinAndStatement,
|
|
2158
2197
|
});
|
|
2159
|
-
join = this.
|
|
2198
|
+
join = this.applyAssociationDefaultScopesToJoin({
|
|
2160
2199
|
dreamClass,
|
|
2161
2200
|
join,
|
|
2162
2201
|
tableNameOrAlias: currentTableAlias,
|
|
2163
2202
|
association,
|
|
2164
|
-
|
|
2203
|
+
modelClassWhoseDefaultScopesApply: modelClassWhoseDefaultScopesApplyToJoin,
|
|
2165
2204
|
});
|
|
2166
|
-
join = this.applyJoinAndStatement(
|
|
2205
|
+
join = this.applyJoinAndStatement(modelClassUsedForJoinConditions, join, joinAndStatement, currentTableAlias);
|
|
2167
2206
|
return join;
|
|
2168
2207
|
});
|
|
2169
2208
|
}
|
|
@@ -2174,8 +2213,8 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2174
2213
|
join = join.onRef(this.namespaceColumn(association.primaryKey(), previousTableAlias), '=', this.namespaceColumn(association.foreignKey(), currentTableAlias));
|
|
2175
2214
|
if (association.polymorphic) {
|
|
2176
2215
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement({
|
|
2177
|
-
[association.foreignKeyTypeField()]:
|
|
2178
|
-
?
|
|
2216
|
+
[association.foreignKeyTypeField()]: polymorphicSourceTargetModelClass
|
|
2217
|
+
? polymorphicSourceTargetModelClass.referenceTypeString
|
|
2179
2218
|
: dreamClass.referenceTypeString,
|
|
2180
2219
|
}, currentTableAlias)));
|
|
2181
2220
|
}
|
|
@@ -2194,14 +2233,14 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2194
2233
|
selfTableAlias,
|
|
2195
2234
|
joinAndStatement,
|
|
2196
2235
|
});
|
|
2197
|
-
join = this.
|
|
2236
|
+
join = this.applyAssociationDefaultScopesToJoin({
|
|
2198
2237
|
dreamClass,
|
|
2199
2238
|
join,
|
|
2200
2239
|
tableNameOrAlias: currentTableAlias,
|
|
2201
2240
|
association,
|
|
2202
|
-
|
|
2241
|
+
modelClassWhoseDefaultScopesApply: modelClassWhoseDefaultScopesApplyToJoin,
|
|
2203
2242
|
});
|
|
2204
|
-
join = this.applyJoinAndStatement(
|
|
2243
|
+
join = this.applyJoinAndStatement(modelClassUsedForJoinConditions, join, joinAndStatement, currentTableAlias);
|
|
2205
2244
|
return join;
|
|
2206
2245
|
});
|
|
2207
2246
|
if (association.type === 'HasMany') {
|
|
@@ -2312,11 +2351,9 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2312
2351
|
if (missingRequiredWhereStatements.length)
|
|
2313
2352
|
throw new MissingRequiredAssociationAndClause(association, missingRequiredWhereStatements[0]);
|
|
2314
2353
|
}
|
|
2315
|
-
|
|
2354
|
+
applyAssociationDefaultScopesToJoin({ dreamClass, join, tableNameOrAlias, association, modelClassWhoseDefaultScopesApply, }) {
|
|
2316
2355
|
let scopesQuery = new Query(this.dreamInstance);
|
|
2317
|
-
const
|
|
2318
|
-
const associationScopes = associationClass['scopes'].default;
|
|
2319
|
-
for (const scope of associationScopes) {
|
|
2356
|
+
for (const scope of modelClassWhoseDefaultScopesApply['scopes'].default) {
|
|
2320
2357
|
if (!shouldBypassDefaultScope(scope.method, {
|
|
2321
2358
|
bypassAllDefaultScopes: this.query['bypassAllDefaultScopes'],
|
|
2322
2359
|
defaultScopesToBypass: [
|
|
@@ -2324,7 +2361,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
2324
2361
|
...(association.withoutDefaultScopes || []),
|
|
2325
2362
|
],
|
|
2326
2363
|
})) {
|
|
2327
|
-
const tempQuery =
|
|
2364
|
+
const tempQuery = modelClassWhoseDefaultScopesApply[scope.method](scopesQuery);
|
|
2328
2365
|
// The scope method on a Dream model should return a clone of the Query it receives
|
|
2329
2366
|
// (e.g. by returning `scope.where(...)`), but in case the function doesn't return,
|
|
2330
2367
|
// or returns the wrong thing, we check before overriding `scopesQuery` with what the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function applyScopeBypassingSettingsToQuery(query, { bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
2
2
|
if (bypassAllDefaultScopes)
|
|
3
|
-
query = query
|
|
3
|
+
query = query['removeAllDefaultScopes']();
|
|
4
4
|
defaultScopesToBypass.forEach(defaultScopeToBypass => {
|
|
5
5
|
query = query.removeDefaultScope(defaultScopeToBypass);
|
|
6
6
|
});
|
|
@@ -5,6 +5,8 @@ export default async function loadedOrLoadAssociation(dream, dreamOrTransactionB
|
|
|
5
5
|
let scope = dreamOrTransactionBuilder.associationQuery(associationName, associationQueryOptions);
|
|
6
6
|
if (options?.passthrough)
|
|
7
7
|
scope = scope.passthrough(options.passthrough);
|
|
8
|
+
if (options?.connection)
|
|
9
|
+
scope = scope.connection(options.connection);
|
|
8
10
|
if (association?.type === 'HasMany') {
|
|
9
11
|
dream[associationName] = (await scope.all());
|
|
10
12
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs one database-sourced scalar as the persisted value without
|
|
3
|
+
* replacing the saved-change history established by the current save.
|
|
4
|
+
*/
|
|
5
|
+
export default function installPersistedAttribute(dream, column, val) {
|
|
6
|
+
dream['currentAttributes'][column] = val;
|
|
7
|
+
dream['frozenAttributes'][column] = val;
|
|
8
|
+
dream['originalAttributes'][column] = val;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -21,7 +21,7 @@ export default async function loadDependentDestroyTree(dream, txn, { reallyDestr
|
|
|
21
21
|
loadBuilder = loadBuilder.load(...args);
|
|
22
22
|
}
|
|
23
23
|
if (bypassAllDefaultScopes) {
|
|
24
|
-
loadBuilder = loadBuilder
|
|
24
|
+
loadBuilder = loadBuilder['removeAllDefaultScopes']();
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
for (const scopeName of defaultScopesToBypass) {
|
|
@@ -10,7 +10,9 @@ export default async function reload(dream, txn = null) {
|
|
|
10
10
|
// we have persisted are not yet propagated
|
|
11
11
|
else
|
|
12
12
|
query = query.connection('primary');
|
|
13
|
-
query = query
|
|
13
|
+
query = query['removeAllDefaultScopes']().where({
|
|
14
|
+
[dream['_primaryKey']]: dream.primaryKeyValue(),
|
|
15
|
+
});
|
|
14
16
|
const reloadedRecord = await query.firstOrFail();
|
|
15
17
|
dream.setAttributes(reloadedRecord.getAttributes());
|
|
16
18
|
dream['freezeAttributes']();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default class IncompatibleThroughAssociationTarget extends Error {
|
|
2
|
+
constructor({ outermostAssociation, outermostTargetModelClass, sourceAssociation, }) {
|
|
3
|
+
super(`Through association \`${outermostAssociation.as}\` targets \`${outermostTargetModelClass.sanitizedName}\`, but source association \`${sourceAssociation.as}\` targets ${targetDescription(sourceAssociation)}. ` +
|
|
4
|
+
`The through association's target must be the same as or a subclass of a source target.`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function targetDescription(association) {
|
|
8
|
+
const targetModelClassOrClasses = association.modelCB();
|
|
9
|
+
const targetNames = (Array.isArray(targetModelClassOrClasses) ? targetModelClassOrClasses : [targetModelClassOrClasses]).map(targetModelClass => `\`${targetModelClass.sanitizedName}\``);
|
|
10
|
+
return targetNames.join(', ');
|
|
11
|
+
}
|
|
@@ -2,7 +2,7 @@ import { CompiledQuery, Selectable } from 'kysely';
|
|
|
2
2
|
import DreamClassTransactionBuilder from './dream/DreamClassTransactionBuilder.js';
|
|
3
3
|
import DreamInstanceTransactionBuilder from './dream/DreamInstanceTransactionBuilder.js';
|
|
4
4
|
import DreamTransaction from './dream/DreamTransaction.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { InstanceDestroyOptions, InstanceUpdateOptions } from './dream/internal/instanceMutationOptions.js';
|
|
6
6
|
import LeftJoinLoadBuilder from './dream/LeftJoinLoadBuilder.js';
|
|
7
7
|
import LoadBuilder from './dream/LoadBuilder.js';
|
|
8
8
|
import Query from './dream/Query.js';
|
|
@@ -594,6 +594,8 @@ export default class Dream {
|
|
|
594
594
|
*/
|
|
595
595
|
static get associationNames(): string[];
|
|
596
596
|
/**
|
|
597
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
598
|
+
*
|
|
597
599
|
* Returns a query which bypasses user-removable default scopes, including on
|
|
598
600
|
* association loads. An STI child's reserved type discriminator remains
|
|
599
601
|
* enforced; query the STI base model to span its registered children.
|
|
@@ -2476,7 +2478,7 @@ export default class Dream {
|
|
|
2476
2478
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
2477
2479
|
* @returns The instance that was destroyed
|
|
2478
2480
|
*/
|
|
2479
|
-
destroy<I extends Dream>(this: I, options?:
|
|
2481
|
+
destroy<I extends Dream>(this: I, options?: InstanceDestroyOptions<I>): Promise<I>;
|
|
2480
2482
|
/**
|
|
2481
2483
|
* Deletes the record represented by this instance
|
|
2482
2484
|
* from the database, calling any destroy
|
|
@@ -2499,7 +2501,7 @@ export default class Dream {
|
|
|
2499
2501
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
2500
2502
|
* @returns The instance that was destroyed
|
|
2501
2503
|
*/
|
|
2502
|
-
reallyDestroy<I extends Dream>(this: I, options?:
|
|
2504
|
+
reallyDestroy<I extends Dream>(this: I, options?: InstanceDestroyOptions<I>): Promise<I>;
|
|
2503
2505
|
/**
|
|
2504
2506
|
* Undestroys a SoftDelete model, unsetting
|
|
2505
2507
|
* the `deletedAt` field in the database.
|
|
@@ -2508,7 +2510,7 @@ export default class Dream {
|
|
|
2508
2510
|
* this will raise an exception.
|
|
2509
2511
|
*
|
|
2510
2512
|
* ```ts
|
|
2511
|
-
* const user = await User.
|
|
2513
|
+
* const user = await User.removeDefaultScope('dream:SoftDelete').last()
|
|
2512
2514
|
* await user.undestroy()
|
|
2513
2515
|
* ```
|
|
2514
2516
|
*
|
|
@@ -2519,7 +2521,7 @@ export default class Dream {
|
|
|
2519
2521
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
2520
2522
|
* @returns The undestroyed record
|
|
2521
2523
|
*/
|
|
2522
|
-
undestroy<I extends Dream>(this: I, options?:
|
|
2524
|
+
undestroy<I extends Dream>(this: I, options?: InstanceDestroyOptions<I>): Promise<I>;
|
|
2523
2525
|
/**
|
|
2524
2526
|
* Returns true if the argument is the same Dream class
|
|
2525
2527
|
* with the same primary key value.
|
|
@@ -2563,23 +2565,21 @@ export default class Dream {
|
|
|
2563
2565
|
* @returns The created association
|
|
2564
2566
|
*/
|
|
2565
2567
|
createAssociation<I extends Dream, AssociationName extends DreamAssociationNames<I>, PossibleArrayAssociationType extends I[AssociationName & keyof I], AssociationType extends PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes?: UpdateableAssociationProperties<I, RestrictedAssociationType>): Promise<NonNullable<AssociationType>>;
|
|
2566
|
-
destroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options:
|
|
2567
|
-
destroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?:
|
|
2568
|
-
reallyDestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options:
|
|
2569
|
-
reallyDestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?:
|
|
2570
|
-
undestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options:
|
|
2571
|
-
undestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?:
|
|
2568
|
+
destroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
|
|
2569
|
+
destroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, null>): Promise<number>;
|
|
2570
|
+
reallyDestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
|
|
2571
|
+
reallyDestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, null>): Promise<number>;
|
|
2572
|
+
undestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
|
|
2573
|
+
undestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: InstanceDestroyOptions<I> & JoinAndStatements<I, DB, Schema, AssociationTableName, null>): Promise<number>;
|
|
2572
2574
|
associationQuery<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, joinAndStatements: JoinAndStatements<AssociationDream, DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Query<AssociationDream, DefaultQueryTypeOptions<AssociationDream, AssociationName & string>>;
|
|
2573
2575
|
associationQuery<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, joinAndStatements?: JoinAndStatements<AssociationDream, DB, Schema, AssociationTableName, null>): Query<AssociationDream, DefaultQueryTypeOptions<AssociationDream, AssociationName & string>>;
|
|
2574
|
-
updateAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], PossibleArrayAssociationType extends I[AssociationName & keyof I], AssociationType extends PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes: UpdateableAssociationProperties<I, RestrictedAssociationType>, updateAssociationOptions: {
|
|
2576
|
+
updateAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], PossibleArrayAssociationType extends I[AssociationName & keyof I], AssociationType extends PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes: UpdateableAssociationProperties<I, RestrictedAssociationType>, updateAssociationOptions: InstanceUpdateOptions & {
|
|
2575
2577
|
bypassAllDefaultScopes?: boolean;
|
|
2576
2578
|
defaultScopesToBypass?: AllDefaultScopeNames<I>[];
|
|
2577
|
-
skipHooks?: boolean;
|
|
2578
2579
|
} & JoinAndStatements<I, DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
|
|
2579
|
-
updateAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], PossibleArrayAssociationType extends I[AssociationName & keyof I], AssociationType extends PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes: UpdateableAssociationProperties<I, RestrictedAssociationType>, updateAssociationOptions?: {
|
|
2580
|
+
updateAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], PossibleArrayAssociationType extends I[AssociationName & keyof I], AssociationType extends PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes: UpdateableAssociationProperties<I, RestrictedAssociationType>, updateAssociationOptions?: InstanceUpdateOptions & {
|
|
2580
2581
|
bypassAllDefaultScopes?: boolean;
|
|
2581
2582
|
defaultScopesToBypass?: AllDefaultScopeNames<I>[];
|
|
2582
|
-
skipHooks?: boolean;
|
|
2583
2583
|
} & JoinAndStatements<I, DB, Schema, AssociationTableName, null>): Promise<number>;
|
|
2584
2584
|
/**
|
|
2585
2585
|
* Sends data through for use as passthrough data
|
|
@@ -2681,23 +2681,32 @@ export default class Dream {
|
|
|
2681
2681
|
* passthrough: { name: 'My Composition' },
|
|
2682
2682
|
* required: { locale: 'de-DE' }
|
|
2683
2683
|
* })
|
|
2684
|
+
*
|
|
2685
|
+
* // With a specific database connection
|
|
2686
|
+
* const comments = await post.association('comments', { connection: 'replica' })
|
|
2684
2687
|
* ```
|
|
2685
2688
|
*
|
|
2686
2689
|
* @param associationName - The name of the BelongsTo, HasOne, or HasMany association
|
|
2687
|
-
* @param options - Optional configuration for required and passthrough clauses
|
|
2690
|
+
* @param options - Optional configuration for required and passthrough clauses and the database connection
|
|
2688
2691
|
* @param options.required - for associations with DreamConst.required `and` clauses
|
|
2689
2692
|
* @param options.passthrough - for associations with DreamConst.passthrough `and` clauses
|
|
2693
|
+
* @param options.connection - the database connection to use when loading the association ('primary' or 'replica')
|
|
2690
2694
|
* @returns The associated model instance(s) or null/empty array if not found
|
|
2691
2695
|
*/
|
|
2692
2696
|
association<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? MaybeAssociationName : never, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], PassthroughOnStatement extends Required<OnStatementForSpecificColumns<I, DB, Schema, AssociationTableName, PassthroughOnClauseKeys<Schema, TableName, AssociationName> & string[]>>, RequiredOnStatement extends Required<OnStatementForSpecificColumns<I, DB, Schema, AssociationTableName, RequiredOnClauseKeys<Schema, TableName, AssociationName> & string[]>>, Opts extends AssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> & DreamAssociationNamesWithRequiredOnClauses<I> ? {
|
|
2693
2697
|
passthrough: PassthroughOnStatement;
|
|
2694
2698
|
required: RequiredOnStatement;
|
|
2699
|
+
connection?: DbConnectionType;
|
|
2695
2700
|
} : AssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> ? {
|
|
2696
2701
|
passthrough: PassthroughOnStatement;
|
|
2702
|
+
connection?: DbConnectionType;
|
|
2697
2703
|
} : AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I> ? {
|
|
2698
2704
|
required: RequiredOnStatement;
|
|
2705
|
+
connection?: DbConnectionType;
|
|
2699
2706
|
} : never, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName> | null>(this: I, associationName: AssociationName, options: Opts): Promise<ReturnType>;
|
|
2700
|
-
association<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? never : MaybeAssociationName, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName> | null>(this: I, associationName: AssociationName
|
|
2707
|
+
association<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? never : MaybeAssociationName, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName> | null>(this: I, associationName: AssociationName, options?: {
|
|
2708
|
+
connection?: DbConnectionType;
|
|
2709
|
+
}): Promise<ReturnType>;
|
|
2701
2710
|
/**
|
|
2702
2711
|
* If the association is already loaded on the instance, it returns the loaded value
|
|
2703
2712
|
* immediately without making a database query. If the association is not loaded,
|
|
@@ -2742,24 +2751,33 @@ export default class Dream {
|
|
|
2742
2751
|
* passthrough: { name: 'My Composition' },
|
|
2743
2752
|
* required: { locale: 'de-DE' }
|
|
2744
2753
|
* })
|
|
2754
|
+
*
|
|
2755
|
+
* // With a specific database connection
|
|
2756
|
+
* const comments = await post.associationOrFail('comments', { connection: 'replica' })
|
|
2745
2757
|
* ```
|
|
2746
2758
|
*
|
|
2747
2759
|
* @param associationName - The name of the BelongsTo, HasOne, or HasMany association
|
|
2748
|
-
* @param options - Optional configuration for required and passthrough clauses
|
|
2760
|
+
* @param options - Optional configuration for required and passthrough clauses and the database connection
|
|
2749
2761
|
* @param options.required - for associations with DreamConst.required `and` clauses
|
|
2750
2762
|
* @param options.passthrough - for associations with DreamConst.passthrough `and` clauses
|
|
2763
|
+
* @param options.connection - the database connection to use when loading the association ('primary' or 'replica')
|
|
2751
2764
|
* @returns The associated model instance(s) (never null for BelongsTo/HasOne)
|
|
2752
2765
|
* @throws RecordNotFound if no associated record exists (BelongsTo/HasOne only)
|
|
2753
2766
|
*/
|
|
2754
2767
|
associationOrFail<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? MaybeAssociationName : never, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table'], DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], PassthroughOnStatement extends Required<OnStatementForSpecificColumns<I, DB, Schema, AssociationTableName, PassthroughOnClauseKeys<Schema, TableName, AssociationName> & string[]>>, RequiredOnStatement extends Required<OnStatementForSpecificColumns<I, DB, Schema, AssociationTableName, RequiredOnClauseKeys<Schema, TableName, AssociationName> & string[]>>, Opts extends AssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> & DreamAssociationNamesWithRequiredOnClauses<I> ? {
|
|
2755
2768
|
passthrough: PassthroughOnStatement;
|
|
2756
2769
|
required: RequiredOnStatement;
|
|
2770
|
+
connection?: DbConnectionType;
|
|
2757
2771
|
} : AssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> ? {
|
|
2758
2772
|
passthrough: PassthroughOnStatement;
|
|
2773
|
+
connection?: DbConnectionType;
|
|
2759
2774
|
} : AssociationName extends DreamAssociationNamesWithRequiredOnClauses<I> ? {
|
|
2760
2775
|
required: RequiredOnStatement;
|
|
2776
|
+
connection?: DbConnectionType;
|
|
2761
2777
|
} : never, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName>>(this: I, associationName: AssociationName, options: Opts): Promise<ReturnType>;
|
|
2762
|
-
associationOrFail<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? never : MaybeAssociationName, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName>>(this: I, associationName: AssociationName
|
|
2778
|
+
associationOrFail<I extends Dream, MaybeAssociationName extends DreamBelongsToAssociationNames<I> | DreamHasOneAssociationNames<I> | DreamHasManyAssociationNames<I>, AssociationName extends MaybeAssociationName extends DreamAssociationNamesWithPassthroughOnClauses<I> | DreamAssociationNamesWithRequiredOnClauses<I> ? never : MaybeAssociationName, ReturnType extends AssociationName extends DreamHasManyAssociationNames<I> ? AssociationNameToDream<I, AssociationName>[] : AssociationNameToDream<I, AssociationName>>(this: I, associationName: AssociationName, options?: {
|
|
2779
|
+
connection?: DbConnectionType;
|
|
2780
|
+
}): Promise<ReturnType>;
|
|
2763
2781
|
/**
|
|
2764
2782
|
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
2765
2783
|
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
@@ -2984,9 +3002,7 @@ export default class Dream {
|
|
|
2984
3002
|
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
2985
3003
|
* @returns void
|
|
2986
3004
|
*/
|
|
2987
|
-
update<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?:
|
|
2988
|
-
skipHooks?: boolean;
|
|
2989
|
-
}): Promise<void>;
|
|
3005
|
+
update<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: InstanceUpdateOptions): Promise<void>;
|
|
2990
3006
|
/**
|
|
2991
3007
|
* Applies all attribute changes passed to the dream,
|
|
2992
3008
|
* bypassing any custom-defined setters,
|
|
@@ -3010,9 +3026,7 @@ export default class Dream {
|
|
|
3010
3026
|
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
3011
3027
|
* @returns - void
|
|
3012
3028
|
*/
|
|
3013
|
-
updateAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?:
|
|
3014
|
-
skipHooks?: boolean;
|
|
3015
|
-
}): Promise<void>;
|
|
3029
|
+
updateAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: InstanceUpdateOptions): Promise<void>;
|
|
3016
3030
|
/**
|
|
3017
3031
|
* Flags a dream model so that it does not
|
|
3018
3032
|
* actually destroy when in a destroy phase.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SelectArg, SelectExpression } from 'kysely';
|
|
2
2
|
import Dream from '../Dream.js';
|
|
3
3
|
import { PassthroughOnClause, WhereStatement } from '../types/associations/shared.js';
|
|
4
|
-
import {
|
|
4
|
+
import { AllDefaultScopeNames, CreateOrFindByExtraOpts, DreamColumnNames, DreamSerializerKey, FindablePropertiesForClass, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateOrCreateByExtraOpts, ValidatedPluckEachColumnNames } from '../types/dream.js';
|
|
5
5
|
import { BaseModelColumnTypes, FindEachOpts, LoadForModifierFn, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from '../types/query.js';
|
|
6
6
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
|
|
7
7
|
import DreamTransaction from './DreamTransaction.js';
|
|
@@ -599,6 +599,8 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
599
599
|
*/
|
|
600
600
|
queryInstance<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I): Query<DreamInstance>;
|
|
601
601
|
/**
|
|
602
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
603
|
+
*
|
|
602
604
|
* Returns a query which bypasses user-removable default scopes, including on
|
|
603
605
|
* association loads. An STI child's reserved type discriminator remains
|
|
604
606
|
* enforced; query the STI base model to span its registered children.
|
|
@@ -612,7 +614,7 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
612
614
|
*
|
|
613
615
|
* @returns A new Query which will prevent a specific default scope from applying
|
|
614
616
|
*/
|
|
615
|
-
removeDefaultScope<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I, scopeName:
|
|
617
|
+
removeDefaultScope<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I, scopeName: AllDefaultScopeNames<DreamInstance>): Query<DreamInstance>;
|
|
616
618
|
/**
|
|
617
619
|
* Returns the last record corresponding to the
|
|
618
620
|
* model, ordered by primary key.
|