@rvoh/dream 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/Dream.js +2 -3
- package/dist/cjs/src/decorators/field/association/BelongsTo.js +3 -0
- package/dist/cjs/src/decorators/field/association/HasMany.js +1 -3
- package/dist/cjs/src/decorators/field/association/HasOne.js +1 -3
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +349 -346
- package/dist/cjs/src/dream/internal/{extractAssociationMetadataFromAssociationName.js → associationStringToNameAndAlias.js} +3 -3
- package/dist/cjs/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.js +14 -0
- package/dist/cjs/src/dream/internal/unaliasTableName.js +2 -2
- package/dist/cjs/src/errors/UnexpectedUndefined.js +1 -3
- package/dist/cjs/src/errors/associations/{ArrayTargetsIncompatibleWithThroughAssociation.js → ArrayTargetIncompatibleWithThroughAssociation.js} +2 -2
- package/dist/cjs/src/errors/associations/ArrayTargetOnlyOnPolymorphicBelongsTo.js +19 -0
- package/dist/cjs/src/errors/associations/JoinAttemptedOnMissingAssociation.js +1 -1
- package/dist/cjs/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.js +20 -0
- package/dist/esm/src/Dream.js +2 -3
- package/dist/esm/src/decorators/field/association/BelongsTo.js +3 -0
- package/dist/esm/src/decorators/field/association/HasMany.js +1 -3
- package/dist/esm/src/decorators/field/association/HasOne.js +1 -3
- package/dist/esm/src/dream/QueryDriver/Kysely.js +349 -346
- package/dist/esm/src/dream/internal/{extractAssociationMetadataFromAssociationName.js → associationStringToNameAndAlias.js} +2 -2
- package/dist/esm/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.js +11 -0
- package/dist/esm/src/dream/internal/unaliasTableName.js +2 -2
- package/dist/esm/src/errors/UnexpectedUndefined.js +1 -3
- package/dist/esm/src/errors/associations/{ArrayTargetsIncompatibleWithThroughAssociation.js → ArrayTargetIncompatibleWithThroughAssociation.js} +1 -1
- package/dist/esm/src/errors/associations/ArrayTargetOnlyOnPolymorphicBelongsTo.js +16 -0
- package/dist/esm/src/errors/associations/JoinAttemptedOnMissingAssociation.js +1 -1
- package/dist/esm/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.js +17 -0
- package/dist/types/src/Dream.d.ts +0 -1
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +55 -27
- package/dist/types/src/dream/internal/associationStringToNameAndAlias.d.ts +4 -0
- package/dist/types/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.d.ts +11 -0
- package/dist/types/src/errors/associations/{ArrayTargetsIncompatibleWithThroughAssociation.d.ts → ArrayTargetIncompatibleWithThroughAssociation.d.ts} +1 -1
- package/dist/types/src/errors/associations/ArrayTargetOnlyOnPolymorphicBelongsTo.d.ts +10 -0
- package/dist/types/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.d.ts +12 -0
- package/dist/types/src/types/associations/shared.d.ts +2 -4
- package/dist/types/src/types/associations/shared.ts +2 -12
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CliFileWriter.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +136 -136
- package/docs/classes/DreamApp.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/DreamSerializerBuilder.html +8 -8
- 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/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/Query.html +60 -60
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.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/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.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/normalizeUnicode.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/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.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/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.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/interfaces/SerializerRendererOpts.html +2 -2
- 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/DbTypes.html +1 -1
- package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.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/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.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/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.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/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.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/OpenapiPrimitiveBaseTypes.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/OpenapiShorthandPrimitiveBaseTypes.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/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.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/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.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/DreamAppAllowedPackageManagersEnumValues.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 +2 -2
- package/CHANGELOG.md +0 -23
- package/dist/cjs/src/errors/associations/CannotAssociateThroughMultiplePolymorphics.js +0 -27
- package/dist/esm/src/errors/associations/CannotAssociateThroughMultiplePolymorphics.js +0 -24
- package/dist/types/src/dream/internal/extractAssociationMetadataFromAssociationName.d.ts +0 -4
- package/dist/types/src/errors/associations/CannotAssociateThroughMultiplePolymorphics.d.ts +0 -17
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default =
|
|
4
|
-
function
|
|
3
|
+
exports.default = associationStringToNameAndAlias;
|
|
4
|
+
function associationStringToNameAndAlias(associationName) {
|
|
5
5
|
if (/ as /.test(associationName)) {
|
|
6
6
|
const [name, alias] = associationName.split(/ as /);
|
|
7
7
|
return { name: name ?? associationName, alias: alias ?? associationName };
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
return { name: associationName, alias:
|
|
10
|
+
return { name: associationName, alias: undefined };
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = throughAssociationHasOptionsBesidesThroughAndSource;
|
|
4
|
+
function throughAssociationHasOptionsBesidesThroughAndSource(throughAssociation) {
|
|
5
|
+
const throughAssocForTesting = throughAssociation;
|
|
6
|
+
return (throughAssocForTesting &&
|
|
7
|
+
(throughAssocForTesting.and ||
|
|
8
|
+
throughAssocForTesting.andAny ||
|
|
9
|
+
throughAssocForTesting.andNot ||
|
|
10
|
+
throughAssocForTesting.distinct ||
|
|
11
|
+
throughAssocForTesting.order ||
|
|
12
|
+
throughAssocForTesting.selfAnd ||
|
|
13
|
+
throughAssocForTesting.selfAndNot));
|
|
14
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = unaliasTableName;
|
|
4
|
-
const
|
|
4
|
+
const associationStringToNameAndAlias_js_1 = require("./associationStringToNameAndAlias.js");
|
|
5
5
|
function unaliasTableName(tableName) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, associationStringToNameAndAlias_js_1.default)(tableName).name;
|
|
7
7
|
}
|
|
@@ -6,9 +6,7 @@ class UnexpectedUndefined extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
get message() {
|
|
8
8
|
return `Undefined detected where it should never happen since we are iterating
|
|
9
|
-
over keys of an internal object that should not have undefined values
|
|
10
|
-
|
|
11
|
-
This was added as part of activating noUncheckedIndexedAccess in tsconfig.`;
|
|
9
|
+
over keys of an internal object that should not have undefined values.`;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
exports.default = UnexpectedUndefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class
|
|
3
|
+
class ArrayTargetIncompatibleWithThroughAssociation extends Error {
|
|
4
4
|
dreamClass;
|
|
5
5
|
association;
|
|
6
6
|
constructor({ dreamClass, association, }) {
|
|
@@ -16,4 +16,4 @@ Association: ${this.association.as}
|
|
|
16
16
|
`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
exports.default =
|
|
19
|
+
exports.default = ArrayTargetIncompatibleWithThroughAssociation;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ArrayTargetOnlyOnPolymorphicBelongsTo extends Error {
|
|
4
|
+
dreamClass;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor({ dreamClass, associationName }) {
|
|
7
|
+
super();
|
|
8
|
+
this.dreamClass = dreamClass;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `
|
|
13
|
+
An array of targets may only be defined on polymorphic BelongsTo associations:
|
|
14
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
15
|
+
Association: ${this.associationName}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = ArrayTargetOnlyOnPolymorphicBelongsTo;
|
|
@@ -10,7 +10,7 @@ class JoinAttemptedOnMissingAssociation extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
get message() {
|
|
12
12
|
return `
|
|
13
|
-
A
|
|
13
|
+
A join call has been attempted on \`${this.dreamClass.sanitizedName}\` association \`${this.associationName}\`,
|
|
14
14
|
but \`${this.dreamClass.sanitizedName}\` does not define association \`${this.associationName}\`.
|
|
15
15
|
|
|
16
16
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ThroughAssociationConditionsIncompatibleWithThroughAssociationSource extends Error {
|
|
4
|
+
dreamClass;
|
|
5
|
+
association;
|
|
6
|
+
constructor({ dreamClass, association, }) {
|
|
7
|
+
super();
|
|
8
|
+
this.dreamClass = dreamClass;
|
|
9
|
+
this.association = association;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `
|
|
13
|
+
Through association options besides \`through\` and \`source\` are incompatible
|
|
14
|
+
with \`source\` associations that are themselves \`through\` associations.
|
|
15
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
16
|
+
Association: ${this.association.as}
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = ThroughAssociationConditionsIncompatibleWithThroughAssociationSource;
|
package/dist/esm/src/Dream.js
CHANGED
|
@@ -13,10 +13,10 @@ import associationUpdateQuery from './dream/internal/associations/associationUpd
|
|
|
13
13
|
import createAssociation from './dream/internal/associations/createAssociation.js';
|
|
14
14
|
import destroyAssociation from './dream/internal/associations/destroyAssociation.js';
|
|
15
15
|
import undestroyAssociation from './dream/internal/associations/undestroyAssociation.js';
|
|
16
|
+
import associationStringToNameAndAlias from './dream/internal/associationStringToNameAndAlias.js';
|
|
16
17
|
import destroyDream from './dream/internal/destroyDream.js';
|
|
17
18
|
import { destroyOptions, reallyDestroyOptions, undestroyOptions, } from './dream/internal/destroyOptions.js';
|
|
18
19
|
import ensureSTITypeFieldIsSet from './dream/internal/ensureSTITypeFieldIsSet.js';
|
|
19
|
-
import extractAssociationMetadataFromAssociationName from './dream/internal/extractAssociationMetadataFromAssociationName.js';
|
|
20
20
|
import findOrCreateBy from './dream/internal/findOrCreateBy.js';
|
|
21
21
|
import reload from './dream/internal/reload.js';
|
|
22
22
|
import runValidations from './dream/internal/runValidations.js';
|
|
@@ -634,7 +634,7 @@ export default class Dream {
|
|
|
634
634
|
* @returns Association metadata for the requested association
|
|
635
635
|
*/
|
|
636
636
|
static getAssociationMetadata(associationName) {
|
|
637
|
-
return this.associationMetadataMap()[
|
|
637
|
+
return this.associationMetadataMap()[associationStringToNameAndAlias(associationName).name];
|
|
638
638
|
}
|
|
639
639
|
/**
|
|
640
640
|
* @internal
|
|
@@ -1810,7 +1810,6 @@ export default class Dream {
|
|
|
1810
1810
|
* // as: 'ratings',
|
|
1811
1811
|
* // polymorphic: true,
|
|
1812
1812
|
* // source: 'ratings',
|
|
1813
|
-
* // preloadThroughColumns: undefined,
|
|
1814
1813
|
* // where: undefined,
|
|
1815
1814
|
* // whereNot: undefined,
|
|
1816
1815
|
* // selfWhere: undefined,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import lookupModelByGlobalNameOrNames from '../../../dream-app/helpers/lookupModelByGlobalNameOrNames.js';
|
|
2
|
+
import ArrayTargetOnlyOnPolymorphicBelongsTo from '../../../errors/associations/ArrayTargetOnlyOnPolymorphicBelongsTo.js';
|
|
2
3
|
import { validatesImplementation } from '../validation/Validates.js';
|
|
3
4
|
import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociationsFactory, finalForeignKey, foreignKeyTypeField, } from './shared.js';
|
|
4
5
|
/**
|
|
@@ -44,6 +45,8 @@ export default function BelongsTo(globalAssociationNameOrNames, opts = {}) {
|
|
|
44
45
|
delete this[key];
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
48
|
+
if (Array.isArray(globalAssociationNameOrNames) && !polymorphic)
|
|
49
|
+
throw new ArrayTargetOnlyOnPolymorphicBelongsTo({ dreamClass, associationName: key });
|
|
47
50
|
const partialAssociation = associationPrimaryKeyAccessors({
|
|
48
51
|
modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
|
|
49
52
|
globalAssociationNameOrNames,
|
|
@@ -26,7 +26,6 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
26
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
|
-
* @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
29
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
31
30
|
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
32
31
|
* @param opts.selfAndNot - Adds a not and-clause to an association between a column on the associated model and a column on this model.
|
|
@@ -35,7 +34,7 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
35
34
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
36
35
|
*/
|
|
37
36
|
export default function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
38
|
-
const { dependent, distinct, foreignKey, and, andNot, andAny, order, polymorphic = false,
|
|
37
|
+
const { dependent, distinct, foreignKey, and, andNot, andAny, order, polymorphic = false, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
39
38
|
return function (_, context) {
|
|
40
39
|
const key = context.name;
|
|
41
40
|
context.addInitializer(function () {
|
|
@@ -68,7 +67,6 @@ export default function HasMany(globalAssociationNameOrNames, opts = {}) {
|
|
|
68
67
|
andNot,
|
|
69
68
|
andAny,
|
|
70
69
|
polymorphic,
|
|
71
|
-
preloadThroughColumns,
|
|
72
70
|
primaryKeyOverride,
|
|
73
71
|
selfAnd,
|
|
74
72
|
selfAndNot,
|
|
@@ -24,7 +24,6 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
24
24
|
* @param opts.andNot - A not and-clause to be applied when this association is loaded
|
|
25
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
|
-
* @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
27
|
* @param opts.primaryKeyOverride - A custom column name to use for the primary key.
|
|
29
28
|
* @param opts.selfAnd - Adds an and-clause to an association between a column on the associated model and a column on this model.
|
|
30
29
|
* @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,7 +32,7 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
33
32
|
* @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
|
|
34
33
|
*/
|
|
35
34
|
export default function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
36
|
-
const { dependent, foreignKey, and, andNot, andAny, polymorphic = false,
|
|
35
|
+
const { dependent, foreignKey, and, andNot, andAny, polymorphic = false, primaryKeyOverride = null, selfAnd, selfAndNot, source, through, withoutDefaultScopes, } = opts;
|
|
37
36
|
return function (_, context) {
|
|
38
37
|
const key = context.name;
|
|
39
38
|
context.addInitializer(function () {
|
|
@@ -66,7 +65,6 @@ export default function HasOne(globalAssociationNameOrNames, opts = {}) {
|
|
|
66
65
|
andNot,
|
|
67
66
|
andAny,
|
|
68
67
|
polymorphic,
|
|
69
|
-
preloadThroughColumns,
|
|
70
68
|
primaryKeyOverride,
|
|
71
69
|
selfAnd,
|
|
72
70
|
selfAndNot,
|