@rvoh/dream 0.29.3 → 0.29.5
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 +58 -1
- package/dist/cjs/src/db/DreamDbConnection.js +7 -1
- package/dist/cjs/src/db/errors.js +10 -3
- package/dist/cjs/src/decorators/STI.js +1 -1
- package/dist/cjs/src/decorators/associations/shared.js +3 -3
- package/dist/cjs/src/decorators/hooks/AfterCreate.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterCreateCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterDestroy.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterDestroyCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterSave.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterSaveCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterUpdate.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterUpdateCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeCreate.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeDestroy.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeSave.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeUpdate.js +1 -1
- package/dist/cjs/src/dream/Query.js +40 -20
- package/dist/cjs/src/dream/internal/associations/createAssociation.js +1 -1
- package/dist/cjs/src/dream/internal/runHooksFor.js +1 -1
- package/dist/cjs/src/dream/internal/saveDream.js +1 -1
- package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +1 -1
- package/dist/cjs/src/dream-application/index.js +6 -0
- package/dist/cjs/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +1 -1
- package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +1 -1
- package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +1 -1
- package/dist/cjs/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +1 -1
- package/dist/cjs/src/errors/CannotReloadUnsavedDream.js +1 -1
- package/dist/cjs/src/errors/CreateOrFindByFailedToCreateAndFind.js +1 -1
- package/dist/cjs/src/errors/DoNotSetEncryptedFieldsDirectly.js +1 -1
- package/dist/cjs/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/cjs/src/errors/MissingSerializersDefinition.js +5 -5
- package/dist/cjs/src/errors/MissingTable.js +4 -4
- package/dist/cjs/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +2 -2
- package/dist/cjs/src/errors/NonExistentScopeProvidedToResort.js +2 -2
- package/dist/cjs/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +3 -3
- package/dist/cjs/src/errors/associations/CanOnlyPassBelongsToModelParam.js +1 -1
- package/dist/cjs/src/errors/associations/CannotAssociateThroughPolymorphic.js +1 -1
- package/dist/cjs/src/errors/associations/CannotCreateAssociationWithThroughContext.js +1 -1
- package/dist/cjs/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +1 -1
- package/dist/cjs/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +1 -1
- package/dist/cjs/src/errors/associations/InvalidComputedForeignKey.js +2 -2
- package/dist/cjs/src/errors/associations/JoinAttemptedOnMissingAssociation.js +4 -4
- package/dist/cjs/src/errors/associations/MissingThroughAssociation.js +4 -4
- package/dist/cjs/src/errors/associations/MissingThroughAssociationSource.js +10 -10
- package/dist/cjs/src/errors/associations/NonLoadedAssociation.js +1 -1
- package/dist/cjs/src/errors/ops/AnyRequiresArrayColumn.js +1 -1
- package/dist/cjs/src/errors/schema-builder/FailedToIdentifyAssociation.js +4 -4
- package/dist/cjs/src/errors/sti/STIChildMissing.js +1 -1
- package/dist/cjs/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +1 -1
- package/dist/cjs/src/helpers/db/loadPgClient.js +6 -0
- package/dist/esm/src/Dream.js +58 -1
- package/dist/esm/src/db/DreamDbConnection.js +7 -1
- package/dist/esm/src/db/errors.js +10 -3
- package/dist/esm/src/decorators/STI.js +1 -1
- package/dist/esm/src/decorators/associations/shared.js +3 -3
- package/dist/esm/src/decorators/hooks/AfterCreate.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterCreateCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterDestroy.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterDestroyCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterSave.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterSaveCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterUpdate.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterUpdateCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeCreate.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeDestroy.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeSave.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeUpdate.js +1 -1
- package/dist/esm/src/dream/Query.js +40 -20
- package/dist/esm/src/dream/internal/associations/createAssociation.js +1 -1
- package/dist/esm/src/dream/internal/runHooksFor.js +1 -1
- package/dist/esm/src/dream/internal/saveDream.js +1 -1
- package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +1 -1
- package/dist/esm/src/dream-application/index.js +6 -0
- package/dist/esm/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +1 -1
- package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +1 -1
- package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +1 -1
- package/dist/esm/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +1 -1
- package/dist/esm/src/errors/CannotReloadUnsavedDream.js +1 -1
- package/dist/esm/src/errors/CreateOrFindByFailedToCreateAndFind.js +1 -1
- package/dist/esm/src/errors/DoNotSetEncryptedFieldsDirectly.js +1 -1
- package/dist/esm/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/esm/src/errors/MissingSerializersDefinition.js +5 -5
- package/dist/esm/src/errors/MissingTable.js +4 -4
- package/dist/esm/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +2 -2
- package/dist/esm/src/errors/NonExistentScopeProvidedToResort.js +2 -2
- package/dist/esm/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +3 -3
- package/dist/esm/src/errors/associations/CanOnlyPassBelongsToModelParam.js +1 -1
- package/dist/esm/src/errors/associations/CannotAssociateThroughPolymorphic.js +1 -1
- package/dist/esm/src/errors/associations/CannotCreateAssociationWithThroughContext.js +1 -1
- package/dist/esm/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +1 -1
- package/dist/esm/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +1 -1
- package/dist/esm/src/errors/associations/InvalidComputedForeignKey.js +2 -2
- package/dist/esm/src/errors/associations/JoinAttemptedOnMissingAssociation.js +4 -4
- package/dist/esm/src/errors/associations/MissingThroughAssociation.js +4 -4
- package/dist/esm/src/errors/associations/MissingThroughAssociationSource.js +10 -10
- package/dist/esm/src/errors/associations/NonLoadedAssociation.js +1 -1
- package/dist/esm/src/errors/ops/AnyRequiresArrayColumn.js +1 -1
- package/dist/esm/src/errors/schema-builder/FailedToIdentifyAssociation.js +4 -4
- package/dist/esm/src/errors/sti/STIChildMissing.js +1 -1
- package/dist/esm/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +1 -1
- package/dist/esm/src/helpers/db/loadPgClient.js +6 -0
- package/dist/types/src/Dream.d.ts +49 -0
- package/dist/types/src/dream/Query.d.ts +11 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +14 -14
- package/docs/classes/Dream.html +146 -122
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +3 -3
- package/docs/classes/DreamImporter.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 +50 -50
- 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/Scope.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/Validate.html +1 -1
- package/docs/functions/Validates.html +1 -1
- package/docs/functions/Virtual.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/db.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/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/validateColumn.html +1 -1
- package/docs/functions/validateTable.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/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/OpenapiSchemaPartialSegment.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/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
|
@@ -365,7 +365,7 @@ export default class Query extends ConnectedToDB {
|
|
|
365
365
|
async findOrFail(primaryKey) {
|
|
366
366
|
const record = await this.find(primaryKey);
|
|
367
367
|
if (!record)
|
|
368
|
-
throw new RecordNotFound(this.dreamInstance
|
|
368
|
+
throw new RecordNotFound(this.dreamInstance['sanitizedConstructorName']);
|
|
369
369
|
return record;
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
@@ -400,7 +400,7 @@ export default class Query extends ConnectedToDB {
|
|
|
400
400
|
async findOrFailBy(whereStatement) {
|
|
401
401
|
const record = await this.findBy(whereStatement);
|
|
402
402
|
if (!record)
|
|
403
|
-
throw new RecordNotFound(this.dreamInstance
|
|
403
|
+
throw new RecordNotFound(this.dreamInstance['sanitizedConstructorName']);
|
|
404
404
|
return record;
|
|
405
405
|
}
|
|
406
406
|
/**
|
|
@@ -1099,6 +1099,9 @@ export default class Query extends ConnectedToDB {
|
|
|
1099
1099
|
// base model, it will be underscored (to match the table name), but when the selected column
|
|
1100
1100
|
// comes back from Kysely camelCased
|
|
1101
1101
|
aliases.push(field.includes('_') ? camelize(field) : field);
|
|
1102
|
+
// namespace the selection so that when plucking the same column name from
|
|
1103
|
+
// multpile tables, they don't get saved as the same name (e.g. select results with two `id` columns,
|
|
1104
|
+
// which the pg package then returns in an object with a single `id` key)
|
|
1102
1105
|
kyselyQuery = kyselyQuery.select(`${this.namespaceColumn(field)} as ${field}`);
|
|
1103
1106
|
});
|
|
1104
1107
|
return (await executeDatabaseQuery(kyselyQuery, 'execute')).map(singleResult => aliases.map(alias => singleResult[alias]));
|
|
@@ -1420,7 +1423,7 @@ export default class Query extends ConnectedToDB {
|
|
|
1420
1423
|
async firstOrFail() {
|
|
1421
1424
|
const record = await this.first();
|
|
1422
1425
|
if (!record)
|
|
1423
|
-
throw new RecordNotFound(this.dreamInstance
|
|
1426
|
+
throw new RecordNotFound(this.dreamInstance['sanitizedConstructorName']);
|
|
1424
1427
|
return record;
|
|
1425
1428
|
}
|
|
1426
1429
|
/**
|
|
@@ -1459,7 +1462,7 @@ export default class Query extends ConnectedToDB {
|
|
|
1459
1462
|
async lastOrFail() {
|
|
1460
1463
|
const record = await this.last();
|
|
1461
1464
|
if (!record)
|
|
1462
|
-
throw new RecordNotFound(this.dreamInstance
|
|
1465
|
+
throw new RecordNotFound(this.dreamInstance['sanitizedConstructorName']);
|
|
1463
1466
|
return record;
|
|
1464
1467
|
}
|
|
1465
1468
|
/**
|
|
@@ -1754,7 +1757,7 @@ export default class Query extends ConnectedToDB {
|
|
|
1754
1757
|
}
|
|
1755
1758
|
async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass, associatedDreams) {
|
|
1756
1759
|
const relevantAssociatedModels = dreams.filter((dream) => {
|
|
1757
|
-
return dream[association.foreignKeyTypeField()] === associatedDreamClass['
|
|
1760
|
+
return dream[association.foreignKeyTypeField()] === associatedDreamClass['stiBaseClassOrOwnClassName'];
|
|
1758
1761
|
});
|
|
1759
1762
|
if (relevantAssociatedModels.length) {
|
|
1760
1763
|
dreams.forEach((dream) => {
|
|
@@ -1777,7 +1780,7 @@ export default class Query extends ConnectedToDB {
|
|
|
1777
1780
|
for (const loadedAssociation of loadedAssociations) {
|
|
1778
1781
|
dreams
|
|
1779
1782
|
.filter((dream) => {
|
|
1780
|
-
return (dream[association.foreignKeyTypeField()] === loadedAssociation['
|
|
1783
|
+
return (dream[association.foreignKeyTypeField()] === loadedAssociation['stiBaseClassOrOwnClassName'] &&
|
|
1781
1784
|
dream[association.foreignKey()] === association.primaryKeyValue(loadedAssociation));
|
|
1782
1785
|
})
|
|
1783
1786
|
.forEach((dream) => {
|
|
@@ -1800,14 +1803,15 @@ export default class Query extends ConnectedToDB {
|
|
|
1800
1803
|
const dream = dreams.find(dream => dream['getAssociationMetadata'](associationName));
|
|
1801
1804
|
if (!dream)
|
|
1802
1805
|
return;
|
|
1803
|
-
const
|
|
1806
|
+
const { name, alias } = extractAssociationMetadataFromAssociationName(associationName);
|
|
1807
|
+
const association = dream['getAssociationMetadata'](name);
|
|
1804
1808
|
const dreamClass = dream.constructor;
|
|
1805
1809
|
const dreamClassToHydrate = association.modelCB();
|
|
1806
1810
|
if ((association.polymorphic && association.type === 'BelongsTo') || Array.isArray(dreamClassToHydrate))
|
|
1807
1811
|
return this.preloadPolymorphicBelongsTo(association, dreams);
|
|
1808
1812
|
const dreamClassToHydrateColumns = [...dreamClassToHydrate.columns()];
|
|
1809
1813
|
const throughColumnsToHydrate = [];
|
|
1810
|
-
const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(),
|
|
1814
|
+
const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(), alias));
|
|
1811
1815
|
const asHasAssociation = association;
|
|
1812
1816
|
if (asHasAssociation.through && asHasAssociation.preloadThroughColumns) {
|
|
1813
1817
|
if (isObject(asHasAssociation.preloadThroughColumns)) {
|
|
@@ -1919,9 +1923,17 @@ export default class Query extends ConnectedToDB {
|
|
|
1919
1923
|
}
|
|
1920
1924
|
return query;
|
|
1921
1925
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1926
|
+
/**
|
|
1927
|
+
* Each association in the chain is pushed onto `throughAssociations`
|
|
1928
|
+
* and `applyOneJoin` is recursively called. The trick is that the
|
|
1929
|
+
* through associations don't get written into the SQL; they
|
|
1930
|
+
* locate the next association we need to build into the SQL,
|
|
1931
|
+
* which is only run by the association that started the `through`
|
|
1932
|
+
* chain. The final association at the end of the `through` chain _is_
|
|
1933
|
+
* written into the SQL as a full association, but the modifications from
|
|
1934
|
+
* the `through` association are only added when the recursion returns
|
|
1935
|
+
* back to the association that kicked off the through associations.
|
|
1936
|
+
*/
|
|
1925
1937
|
joinsBridgeThroughAssociations({ query, dreamClass, association, previousAssociationTableOrAlias, throughAssociations, joinType, }) {
|
|
1926
1938
|
if (association.type === 'BelongsTo' || !association.through) {
|
|
1927
1939
|
return {
|
|
@@ -2002,25 +2014,33 @@ export default class Query extends ConnectedToDB {
|
|
|
2002
2014
|
previousAssociationTableOrAlias = results.previousAssociationTableOrAlias;
|
|
2003
2015
|
const throughClass = results.throughClass;
|
|
2004
2016
|
if (timeToApplyThroughAssociations) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2017
|
+
/**
|
|
2018
|
+
* Each association in the chain is pushed onto `throughAssociations`
|
|
2019
|
+
* and `applyOneJoin` is recursively called. The trick is that the
|
|
2020
|
+
* through associations don't get written into the SQL; they
|
|
2021
|
+
* locate the next association we need to build into the SQL,
|
|
2022
|
+
* which is only run by the association that started the `through`
|
|
2023
|
+
* chain (thus the
|
|
2024
|
+
* `throughAssociations.length && throughAssociations[0].source === association.as`
|
|
2025
|
+
* above). The final association at the end of the `through` chain _is_
|
|
2026
|
+
* written into the SQL as a full association, but the modifications from
|
|
2027
|
+
* the `through` association are only added when the recursion returns
|
|
2028
|
+
* back to the association that kicked off the through associations.
|
|
2029
|
+
*/
|
|
2010
2030
|
throughAssociations.forEach((throughAssociation) => {
|
|
2011
2031
|
if (throughAssociation.type === 'HasMany') {
|
|
2012
2032
|
if (query?.distinctOn && throughAssociation.distinct) {
|
|
2013
2033
|
query = query.distinctOn(this.distinctColumnNameForAssociation({
|
|
2014
2034
|
association: throughAssociation,
|
|
2015
|
-
tableNameOrAlias:
|
|
2035
|
+
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2016
2036
|
foreignKey: throughAssociation.primaryKey(),
|
|
2017
2037
|
}));
|
|
2018
2038
|
}
|
|
2019
2039
|
if (throughAssociation.order) {
|
|
2020
2040
|
query = this.applyOrderStatementForAssociation({
|
|
2021
2041
|
query,
|
|
2022
|
-
tableNameOrAlias: throughAssociation.as,
|
|
2023
2042
|
association: throughAssociation,
|
|
2043
|
+
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2024
2044
|
});
|
|
2025
2045
|
}
|
|
2026
2046
|
}
|
|
@@ -2070,8 +2090,8 @@ export default class Query extends ConnectedToDB {
|
|
|
2070
2090
|
if (association.polymorphic) {
|
|
2071
2091
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement({
|
|
2072
2092
|
[association.foreignKeyTypeField()]: throughClass
|
|
2073
|
-
? throughClass['
|
|
2074
|
-
: dreamClass['
|
|
2093
|
+
? throughClass['stiBaseClassOrOwnClassName']
|
|
2094
|
+
: dreamClass['stiBaseClassOrOwnClassName'],
|
|
2075
2095
|
}, currentAssociationTableOrAlias)));
|
|
2076
2096
|
}
|
|
2077
2097
|
if (timeToApplyThroughAssociations) {
|
|
@@ -25,7 +25,7 @@ export default async function createAssociation(dream, txn = null, associationNa
|
|
|
25
25
|
...opts,
|
|
26
26
|
};
|
|
27
27
|
if (hasAssociation.polymorphic) {
|
|
28
|
-
modifiedOpts[hasAssociation.foreignKeyTypeField()] = dream['
|
|
28
|
+
modifiedOpts[hasAssociation.foreignKeyTypeField()] = dream['stiBaseClassOrOwnClassName'];
|
|
29
29
|
}
|
|
30
30
|
if (txn) {
|
|
31
31
|
hasresult = await associationClass.txn(txn).create(modifiedOpts);
|
|
@@ -51,7 +51,7 @@ export async function runHook(statement, dream, txn) {
|
|
|
51
51
|
Attempting to run ${statement.method} as part of the ${statement.type}
|
|
52
52
|
Dream model hook sequence, but we encountered a method that does not exist.
|
|
53
53
|
|
|
54
|
-
Please make sure "${statement.method}" is defined on ${dream
|
|
54
|
+
Please make sure "${statement.method}" is defined on ${dream['sanitizedConstructorName']}
|
|
55
55
|
`);
|
|
56
56
|
}
|
|
57
57
|
await dream[statement.method](txn);
|
|
@@ -20,7 +20,7 @@ export default async function saveDream(dream, txn = null, { skipHooks = false }
|
|
|
20
20
|
// need to check validations after running before hooks, or else
|
|
21
21
|
// model hooks that might make a model valid cannot run
|
|
22
22
|
if (dream.isInvalid)
|
|
23
|
-
throw new ValidationError(dream
|
|
23
|
+
throw new ValidationError(dream['sanitizedConstructorName'], dream.errors);
|
|
24
24
|
if (alreadyPersisted && !dream.isDirty)
|
|
25
25
|
return dream;
|
|
26
26
|
let query;
|
|
@@ -25,7 +25,7 @@ export default function sqlResultToDreamInstance(dreamClass, sqlResult) {
|
|
|
25
25
|
export function findExtendingDreamClass(dreamClass, type) {
|
|
26
26
|
if (!dreamClass['extendedBy'])
|
|
27
27
|
return undefined;
|
|
28
|
-
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass.
|
|
28
|
+
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass.sanitizedName === type);
|
|
29
29
|
if (extendingDreamClass)
|
|
30
30
|
return extendingDreamClass;
|
|
31
31
|
return dreamClass['extendedBy']
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// after building for esm, importing pg using the following:
|
|
2
|
+
//
|
|
3
|
+
// import * as pg from 'pg'
|
|
4
|
+
//
|
|
5
|
+
// will crash. This is difficult to discover, since it only happens
|
|
6
|
+
// when being imported from our esm build.
|
|
1
7
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
8
|
// @ts-ignore
|
|
3
9
|
import pg from 'pg';
|
|
@@ -10,7 +10,7 @@ Cannot call "undestroy" on a non-SoftDelete model. Ensure that your
|
|
|
10
10
|
model has @SoftDelete applied before calling "undestroy":
|
|
11
11
|
|
|
12
12
|
@SoftDelete()
|
|
13
|
-
class ${this.dreamClass.
|
|
13
|
+
class ${this.dreamClass.sanitizedName} extends ApplicationModel {
|
|
14
14
|
...
|
|
15
15
|
}
|
|
16
16
|
`;
|
|
@@ -10,7 +10,7 @@ export default class CannotDefineAssociationWithBothDependentAndPassthrough exte
|
|
|
10
10
|
return `
|
|
11
11
|
Cannot define association with both "dependent" and "DreamConst.passthrough".
|
|
12
12
|
Error found when trying to parse "${this.associationName}" on the
|
|
13
|
-
${this.dreamClass.
|
|
13
|
+
${this.dreamClass.sanitizedName} dream class.
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -10,7 +10,7 @@ export default class CannotDefineAssociationWithBothDependentAndRequiredOnClause
|
|
|
10
10
|
return `
|
|
11
11
|
Cannot define association with both "dependent" and "DreamConst.required".
|
|
12
12
|
Error found when trying to parse "${this.associationName}" on the
|
|
13
|
-
${this.dreamClass.
|
|
13
|
+
${this.dreamClass.sanitizedName} dream class.
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -10,7 +10,7 @@ export default class CannotPassUndefinedAsAValueToAWhereClause extends Error {
|
|
|
10
10
|
return `
|
|
11
11
|
Cannot pass undefined as a value to a where clause.
|
|
12
12
|
|
|
13
|
-
dream class: ${this.dreamClass.
|
|
13
|
+
dream class: ${this.dreamClass.sanitizedName}
|
|
14
14
|
key receiving an undefined value: ${this.key}
|
|
15
15
|
`;
|
|
16
16
|
}
|
|
@@ -6,7 +6,7 @@ export default class CreateOrFindByFailedToCreateAndFind extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
get message() {
|
|
8
8
|
return `
|
|
9
|
-
Failed to create instance of ${this.dreamClass.
|
|
9
|
+
Failed to create instance of ${this.dreamClass.sanitizedName} and no matching model exists.
|
|
10
10
|
|
|
11
11
|
The likely cause is that one of the \`createWith\` fields violates
|
|
12
12
|
a uniqueness constraint.
|
|
@@ -13,7 +13,7 @@ export default class DoNotSetEncryptedFieldsDirectly extends Error {
|
|
|
13
13
|
Do not set @Encrypted columns directly. Instead, set their accessors, so that
|
|
14
14
|
those fields can be encrypted by Dream internally.
|
|
15
15
|
|
|
16
|
-
Dream class: ${this.dreamClass.
|
|
16
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
17
17
|
Problematic setter: ${this.encryptedColumnName}
|
|
18
18
|
Setter to be used instead: ${this.encryptedProperty}`;
|
|
19
19
|
}
|
|
@@ -12,7 +12,7 @@ Whenever the using SoftDelete decorator, you must have either a deletedAt column
|
|
|
12
12
|
or else another column defined, along with an ovrriding getter on your model, like so:
|
|
13
13
|
|
|
14
14
|
@SoftDelete()
|
|
15
|
-
class ${this.dreamClass.
|
|
15
|
+
class ${this.dreamClass.sanitizedName} extends ApplicationModel {
|
|
16
16
|
public get deletedAtField() {
|
|
17
17
|
return 'customDeletedAtField' as const
|
|
18
18
|
}
|
|
@@ -7,14 +7,14 @@ export default class MissingSerializersDefinition extends Error {
|
|
|
7
7
|
get message() {
|
|
8
8
|
return `
|
|
9
9
|
Missing serializers definition on the following class
|
|
10
|
-
Dream class: ${this.dreamClass.
|
|
10
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
11
11
|
|
|
12
|
-
Try something like this in your ${this.dreamClass.
|
|
12
|
+
Try something like this in your ${this.dreamClass.sanitizedName}'s serializer getter:
|
|
13
13
|
|
|
14
|
-
class ${this.dreamClass.
|
|
15
|
-
public get serializers(): DreamSerializers<${this.dreamClass.
|
|
14
|
+
class ${this.dreamClass.sanitizedName} {
|
|
15
|
+
public get serializers(): DreamSerializers<${this.dreamClass.sanitizedName}> {
|
|
16
16
|
return {
|
|
17
|
-
default: '${this.dreamClass.
|
|
17
|
+
default: '${this.dreamClass.sanitizedName}Serializer'
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
...
|
|
@@ -9,14 +9,14 @@ export default class MissingTable extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Missing table definition on the following dream class:
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
|
|
14
|
-
Try something like this in your ${this.dreamClass.
|
|
14
|
+
Try something like this in your ${this.dreamClass.sanitizedName}'s table getter:
|
|
15
15
|
|
|
16
|
-
class ${this.dreamClass.
|
|
16
|
+
class ${this.dreamClass.sanitizedName} {
|
|
17
17
|
...
|
|
18
18
|
public get table() {
|
|
19
|
-
return '${pluralize(snakeify(this.dreamClass.
|
|
19
|
+
return '${pluralize(snakeify(this.dreamClass.sanitizedName))}'
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
@@ -10,10 +10,10 @@ export default class NonBelongsToAssociationProvidedAsSortableDecoratorScope ext
|
|
|
10
10
|
return `
|
|
11
11
|
Only BelongsTo associations are supported as scopes for the @Sortable decorator.
|
|
12
12
|
received:
|
|
13
|
-
dream model class: ${this.dreamClass.
|
|
13
|
+
dream model class: ${this.dreamClass.sanitizedName}
|
|
14
14
|
scope: ${this.scope}
|
|
15
15
|
|
|
16
|
-
BelongsTo scopes on ${this.dreamClass.
|
|
16
|
+
BelongsTo scopes on ${this.dreamClass.sanitizedName} are:
|
|
17
17
|
${this.dreamClass['associationMetadataByType'].belongsTo.map(assoc => assoc.as).join('\n ')}
|
|
18
18
|
`;
|
|
19
19
|
}
|
|
@@ -10,10 +10,10 @@ export default class NonExistentScopeProvidedToResort extends Error {
|
|
|
10
10
|
return `
|
|
11
11
|
Only BelongsTo scopes are supported by the #resort method
|
|
12
12
|
received:
|
|
13
|
-
dream model class: ${this.dreamClass.
|
|
13
|
+
dream model class: ${this.dreamClass.sanitizedName}
|
|
14
14
|
scope: ${this.scopes.join(', ')}
|
|
15
15
|
|
|
16
|
-
BelongsTo scopes on ${this.dreamClass.
|
|
16
|
+
BelongsTo scopes on ${this.dreamClass.sanitizedName} are:
|
|
17
17
|
${this.dreamClass['sortableFields'].map(conf => conf.positionField).join('\n ')}
|
|
18
18
|
`;
|
|
19
19
|
}
|
|
@@ -10,13 +10,13 @@ export default class SortableDecoratorRequiresColumnOrBelongsToAssociation exten
|
|
|
10
10
|
return `
|
|
11
11
|
Only Column or BelongsTo scopes are supported by the @Sortable decorator.
|
|
12
12
|
received:
|
|
13
|
-
dream model class: ${this.dreamClass.
|
|
13
|
+
dream model class: ${this.dreamClass.sanitizedName}
|
|
14
14
|
scope: ${this.attributeOrScope}
|
|
15
15
|
|
|
16
|
-
Columns on ${this.dreamClass.
|
|
16
|
+
Columns on ${this.dreamClass.sanitizedName} are:
|
|
17
17
|
${[...this.dreamClass.columns()].join('\n ')}
|
|
18
18
|
|
|
19
|
-
BelongsTo scopes on ${this.dreamClass.
|
|
19
|
+
BelongsTo scopes on ${this.dreamClass.sanitizedName} are:
|
|
20
20
|
${this.dreamClass['associationMetadataByType'].belongsTo.map(assoc => assoc.as).join('\n ')}
|
|
21
21
|
`;
|
|
22
22
|
}
|
|
@@ -9,7 +9,7 @@ export default class CanOnlyPassBelongsToModelParam extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Can only pass BelongsTo associated models as params
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
Association: ${this.association.as}
|
|
14
14
|
Association type: ${this.association.type}
|
|
15
15
|
`;
|
|
@@ -9,7 +9,7 @@ export default class CannotAssociateThroughPolymorphic extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Cannot join through a polymorphic association
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
Association: ${this.association.as}
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
@@ -9,7 +9,7 @@ export default class CannotCreateAssociationWithThroughContext extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
'createAssociation' is not supported for through associations.
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
Association: ${this.association.as}
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
@@ -13,7 +13,7 @@ export default class CannotJoinPolymorphicBelongsToError extends Error {
|
|
|
13
13
|
get message() {
|
|
14
14
|
return `
|
|
15
15
|
Cannot join on a polymorphic BelongsTo
|
|
16
|
-
Dream class: ${this.dreamClass.
|
|
16
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
17
17
|
Association: ${this.association.as}
|
|
18
18
|
Inner Join statements:
|
|
19
19
|
${JSON.stringify(this.innerJoinStatements, null, 2)}
|
|
@@ -9,7 +9,7 @@ export default class CannotPassNullOrUndefinedToRequiredBelongsTo extends Error
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Cannot pass null or undefined as a value to a required association.
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
Association: ${this.association.as}
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
@@ -14,7 +14,7 @@ export class InvalidComputedForeignKey extends Error {
|
|
|
14
14
|
get message() {
|
|
15
15
|
return `
|
|
16
16
|
Add an explicit foreignKey declaration to this association declaration:
|
|
17
|
-
Dream class: ${this.dreamClass.
|
|
17
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
18
18
|
Association: ${this.partialAssociation.as}
|
|
19
19
|
Dream tried ${this.computedForeignKey} automatically, but it isn't a column in table ${this.table}.
|
|
20
20
|
`;
|
|
@@ -36,7 +36,7 @@ export class ExplicitForeignKeyRequired extends Error {
|
|
|
36
36
|
return `
|
|
37
37
|
${this.explicitForeignKey} is not a valid column on table ${this.table}.
|
|
38
38
|
Fix the foreignKey declaration on:
|
|
39
|
-
Dream class: ${this.dreamClass.
|
|
39
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
40
40
|
Association: ${this.partialAssociation.as}
|
|
41
41
|
`;
|
|
42
42
|
}
|
|
@@ -8,15 +8,15 @@ export default class JoinAttemptedOnMissingAssociation extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
|
-
A joins call has been attempted on \`${this.dreamClass.
|
|
12
|
-
but \`${this.dreamClass.
|
|
11
|
+
A joins call has been attempted on \`${this.dreamClass.sanitizedName}\` association \`${this.associationName}\`,
|
|
12
|
+
but \`${this.dreamClass.sanitizedName}\` does not define association \`${this.associationName}\`.
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
Either \`${this.associationName}\` is a typo in the joins statement, or association \`${this.associationName}\` needs to be defined on \`${this.dreamClass.name}\`, for example:
|
|
16
16
|
|
|
17
|
-
class ${this.dreamClass.
|
|
17
|
+
class ${this.dreamClass.sanitizedName} {
|
|
18
18
|
...
|
|
19
|
-
@${this.dreamClass.
|
|
19
|
+
@${this.dreamClass.sanitizedName}.HasMany('SomeModelClass')
|
|
20
20
|
public ${this.associationName}: SomeModelClass[]
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
@@ -8,15 +8,15 @@ export default class MissingThroughAssociation extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
|
-
\`${this.dreamClass.
|
|
11
|
+
\`${this.dreamClass.sanitizedName}\` defines through association \`${this.association.through}\`, but \`${this.dreamClass.name}\` does not define association \`${this.association.through}\`.
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
To fix, define association \`${this.association.through}\` on \`${this.dreamClass.
|
|
14
|
+
To fix, define association \`${this.association.through}\` on \`${this.dreamClass.sanitizedName}\`.
|
|
15
15
|
For example:
|
|
16
16
|
|
|
17
|
-
class ${this.dreamClass.
|
|
17
|
+
class ${this.dreamClass.sanitizedName} {
|
|
18
18
|
...
|
|
19
|
-
@${this.dreamClass.
|
|
19
|
+
@${this.dreamClass.sanitizedName}.HasMany('TheJoinModelClass')
|
|
20
20
|
public ${this.association.through}: TheJoinModelClass[]
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
@@ -10,29 +10,29 @@ export default class MissingThroughAssociationSource extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
get message() {
|
|
12
12
|
return `
|
|
13
|
-
\`${this.dreamClass.
|
|
13
|
+
\`${this.dreamClass.sanitizedName}\` defines association \`${this.association.as}\` through \`${this.dreamClass.sanitizedName}\` association \`${this.association.through}\`.
|
|
14
14
|
|
|
15
|
-
\`${this.dreamClass.
|
|
15
|
+
\`${this.dreamClass.sanitizedName}\` association \`${this.association.through}\` points to \`${this.throughClass.sanitizedName}\`.
|
|
16
16
|
|
|
17
|
-
Dream expects association \`${this.association.source}\` to be defiend on \`${this.throughClass.
|
|
17
|
+
Dream expects association \`${this.association.source}\` to be defiend on \`${this.throughClass.sanitizedName}\`, but \`${this.throughClass.sanitizedName}\` does not define association \`${this.association.source}\`.
|
|
18
18
|
|
|
19
19
|
There are two possible fixes:
|
|
20
20
|
|
|
21
21
|
1. Provide an explicit \`source\` in addition to \`through\`.
|
|
22
22
|
|
|
23
|
-
class ${this.dreamClass.
|
|
23
|
+
class ${this.dreamClass.sanitizedName} {
|
|
24
24
|
...
|
|
25
|
-
@${this.dreamClass.name}.HasMany(() => ${this.throughClass.
|
|
26
|
-
public ${this.association.as}: ${this.throughClass.
|
|
25
|
+
@${this.dreamClass.name}.HasMany(() => ${this.throughClass.sanitizedName}, { through: '${this.association.through}', source: '<a valid association on ${this.throughClass.sanitizedName}>'})
|
|
26
|
+
public ${this.association.as}: ${this.throughClass.sanitizedName}[]
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
2. Define association \`${this.association.source}\` on \`${this.throughClass.
|
|
29
|
+
2. Define association \`${this.association.source}\` on \`${this.throughClass.sanitizedName}\`.
|
|
30
30
|
For example:
|
|
31
31
|
|
|
32
|
-
class ${this.throughClass.
|
|
32
|
+
class ${this.throughClass.sanitizedName} {
|
|
33
33
|
...
|
|
34
|
-
@${this.throughClass.
|
|
35
|
-
public ${this.association.source}: ${this.association.modelCB().
|
|
34
|
+
@${this.throughClass.sanitizedName}.HasMany(() => ${this.association.modelCB().name})
|
|
35
|
+
public ${this.association.source}: ${this.association.modelCB().sanitizedName}[]
|
|
36
36
|
}
|
|
37
37
|
`;
|
|
38
38
|
}
|
|
@@ -8,7 +8,7 @@ export default class NonLoadedAssociation extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
|
-
Attempting to access \`${this.associationName}\` on an instance of \`${this.dreamClass.
|
|
11
|
+
Attempting to access \`${this.associationName}\` on an instance of \`${this.dreamClass.sanitizedName}\`,
|
|
12
12
|
but \`${this.associationName}\` has not been preloaded or loaded.
|
|
13
13
|
`;
|
|
14
14
|
}
|
|
@@ -9,7 +9,7 @@ export default class AnyRequiresArrayColumn extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Attempting to call where({ ${this.column}: ops.any(<some value>)} ),
|
|
12
|
-
but ${this.dreamClass.
|
|
12
|
+
but ${this.dreamClass.sanitizedName}#${this.column} is not an array in the database.
|
|
13
13
|
`;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -22,7 +22,7 @@ An unexpected error occurred while looking up an association that you have defin
|
|
|
22
22
|
|
|
23
23
|
While building the schema for your app, we failed to find a match for
|
|
24
24
|
the ${this.associationType} association "${this.associationName}" on the
|
|
25
|
-
${this.modelClass.
|
|
25
|
+
${this.modelClass.sanitizedName} model.
|
|
26
26
|
|
|
27
27
|
This method requires either a string or string array as the first argument,
|
|
28
28
|
to the ${this.associationType} decorator. However, we received the following:
|
|
@@ -34,7 +34,7 @@ to the ${this.associationType} decorator. However, we received the following:
|
|
|
34
34
|
"${typeof attemptedName}"
|
|
35
35
|
|
|
36
36
|
Details:
|
|
37
|
-
dream: ${this.modelClass.
|
|
37
|
+
dream: ${this.modelClass.sanitizedName} (${this.modelClass.globalName})
|
|
38
38
|
association type: ${this.associationType}
|
|
39
39
|
association name: ${this.associationName}
|
|
40
40
|
".
|
|
@@ -51,7 +51,7 @@ An unexpected error occurred while looking up an association that you have defin
|
|
|
51
51
|
|
|
52
52
|
While building the schema for your app, we failed to find a match for
|
|
53
53
|
the ${this.associationType} association "${this.associationName}"
|
|
54
|
-
on ${this.modelClass.
|
|
54
|
+
on ${this.modelClass.sanitizedName}, using the global model name "${attemptedName}".
|
|
55
55
|
|
|
56
56
|
Usually, this is because the global name for
|
|
57
57
|
the model is not what you anticipated, which often happens when you are
|
|
@@ -63,7 +63,7 @@ first argument to an association, since it can help to catch these
|
|
|
63
63
|
familiar gotchas.
|
|
64
64
|
|
|
65
65
|
Details:
|
|
66
|
-
dream: ${this.modelClass.
|
|
66
|
+
dream: ${this.modelClass.sanitizedName} (${this.modelClass.globalName})
|
|
67
67
|
association type: ${this.associationType}
|
|
68
68
|
association name: ${this.associationName}
|
|
69
69
|
attempted model name: ${attemptedName}
|
|
@@ -11,7 +11,7 @@ export default class STIChildMissing extends Error {
|
|
|
11
11
|
get message() {
|
|
12
12
|
return `
|
|
13
13
|
Missing STI child class
|
|
14
|
-
Base Dream class: ${this.baseDreamClass.
|
|
14
|
+
Base Dream class: ${this.baseDreamClass.sanitizedName}
|
|
15
15
|
Type specified in DB record: ${this.extendingDreamClassName}
|
|
16
16
|
Table: ${this.baseDreamClass.table}
|
|
17
17
|
Primary key value: ${this.primaryKeyValue}
|
|
@@ -8,7 +8,7 @@ export default class StiChildIncompatibleWithSoftDeleteDecorator extends Error {
|
|
|
8
8
|
return `
|
|
9
9
|
@SoftDelete decorator cannot be applied to STI children.
|
|
10
10
|
Apply @SoftDelete to the base STI class instead.
|
|
11
|
-
STI child class: ${this.childStiDreamClass.
|
|
11
|
+
STI child class: ${this.childStiDreamClass.sanitizedName}
|
|
12
12
|
`;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// after building for esm, importing pg using the following:
|
|
2
|
+
//
|
|
3
|
+
// import * as pg from 'pg'
|
|
4
|
+
//
|
|
5
|
+
// will crash. This is difficult to discover, since it only happens
|
|
6
|
+
// when being imported from our esm build.
|
|
1
7
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
8
|
// @ts-ignore
|
|
3
9
|
import pg from 'pg';
|