@payloadcms/drizzle 4.0.0-internal.5b1e7cd → 4.0.0-internal.5d2e3d1
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/LICENSE.md +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +25 -3
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.js +8 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +29 -4
- package/dist/countVersions.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +17 -2
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +2 -7
- package/dist/createTableName.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +12 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteBranchGlobal.d.ts +10 -0
- package/dist/deleteBranchGlobal.d.ts.map +1 -0
- package/dist/deleteBranchGlobal.js +27 -0
- package/dist/deleteBranchGlobal.js.map +1 -0
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +25 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/postgres.d.ts +5 -1
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +5 -1
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +3 -1
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +3 -1
- package/dist/exports/sqlite.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts +3 -2
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +2 -1
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.d.ts +40 -0
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinQuery.js +163 -0
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts +20 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.js +301 -0
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +38 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.js +200 -0
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -0
- package/dist/find/findMany.d.ts +6 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +16 -3
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +3 -2
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +83 -200
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +32 -4
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +104 -8
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +24 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +8 -3
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +30 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +32 -5
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +6 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -9
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +41 -15
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts +2 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +17 -4
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +26 -9
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts +2 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +20 -5
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts +2 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +18 -4
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.d.ts +2 -1
- package/dist/migrateStatus.d.ts.map +1 -1
- package/dist/migrateStatus.js +11 -6
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/createJSONQuery/index.js +3 -3
- package/dist/postgres/createJSONQuery/index.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/insert.d.ts.map +1 -1
- package/dist/postgres/insert.js +4 -2
- package/dist/postgres/insert.js.map +1 -1
- package/dist/postgres/predefinedMigrations/localize-status/index.d.ts +11 -0
- package/dist/postgres/predefinedMigrations/localize-status/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/index.js +296 -0
- package/dist/postgres/predefinedMigrations/localize-status/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.d.ts +13 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.js +51 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.js.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.d.ts +13 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.js +54 -0
- package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.js.map +1 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts +35 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js +185 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +8 -4
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +2 -2
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
- package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
- package/dist/postgres/query/postgresUnaccent.js +40 -0
- package/dist/postgres/query/postgresUnaccent.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts +4 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -1
- package/dist/postgres/requireDrizzleKit.js +16 -10
- package/dist/postgres/requireDrizzleKit.js.map +1 -1
- package/dist/postgres/schema/geometryColumn.d.ts +2 -2
- package/dist/postgres/types.d.ts +17 -2
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/addJoinTable.d.ts +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +3 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildBranchVisibility.d.ts +11 -0
- package/dist/queries/buildBranchVisibility.d.ts.map +1 -0
- package/dist/queries/buildBranchVisibility.js +48 -0
- package/dist/queries/buildBranchVisibility.js.map +1 -0
- package/dist/queries/buildOperatorConstraint.d.ts +22 -0
- package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
- package/dist/queries/buildOperatorConstraint.js +79 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -0
- package/dist/queries/buildOrderBy.d.ts +3 -2
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +8 -2
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +3 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +4 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +15 -5
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +233 -58
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +7 -3
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +3 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +266 -11
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/resolveRelationshipPath.d.ts +36 -0
- package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
- package/dist/queries/resolveRelationshipPath.js +66 -0
- package/dist/queries/resolveRelationshipPath.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +6 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queries/validateOperatorHandlers.d.ts +8 -0
- package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
- package/dist/queries/validateOperatorHandlers.js +30 -0
- package/dist/queries/validateOperatorHandlers.js.map +1 -0
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +27 -5
- package/dist/queryDrafts.js.map +1 -1
- package/dist/schema/build.d.ts +3 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +30 -21
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/buildRawSchema.d.ts.map +1 -1
- package/dist/schema/buildRawSchema.js +2 -0
- package/dist/schema/buildRawSchema.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +2 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +13 -9
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +3 -2
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.js +6 -5
- package/dist/sqlite/createJSONQuery/index.js.map +1 -1
- package/dist/sqlite/createRequireDrizzleKit.d.ts +6 -0
- package/dist/sqlite/createRequireDrizzleKit.d.ts.map +1 -0
- package/dist/sqlite/createRequireDrizzleKit.js +15 -0
- package/dist/sqlite/createRequireDrizzleKit.js.map +1 -0
- package/dist/sqlite/execute.js.map +1 -1
- package/dist/sqlite/insert.d.ts.map +1 -1
- package/dist/sqlite/insert.js +9 -4
- package/dist/sqlite/insert.js.map +1 -1
- package/dist/sqlite/predefinedMigrations/localize-status/index.d.ts +28 -0
- package/dist/sqlite/predefinedMigrations/localize-status/index.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/localize-status/index.js +198 -0
- package/dist/sqlite/predefinedMigrations/localize-status/index.js.map +1 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.d.ts +12 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.js +24 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.js.map +1 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.d.ts +12 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.js +28 -0
- package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.js.map +1 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts +15 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js +114 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- package/dist/sqlite/types.d.ts +4 -0
- package/dist/sqlite/types.d.ts.map +1 -1
- package/dist/sqlite/types.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +13 -5
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +2 -5
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +11 -3
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +3 -2
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +2 -1
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +3 -2
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +5 -2
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js +5 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +2 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +53 -24
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/transform/write/types.d.ts +7 -0
- package/dist/transform/write/types.d.ts.map +1 -1
- package/dist/transform/write/types.js.map +1 -1
- package/dist/types.d.ts +53 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts +5 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +96 -4
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +37 -0
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +94 -4
- package/dist/updateOne.js.map +1 -1
- package/dist/upsertBranchGlobalChange.d.ts +3 -0
- package/dist/upsertBranchGlobalChange.d.ts.map +1 -0
- package/dist/upsertBranchGlobalChange.js +35 -0
- package/dist/upsertBranchGlobalChange.js.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +17 -12
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
- package/dist/upsertRow/handleUpsertError.d.ts.map +1 -1
- package/dist/upsertRow/handleUpsertError.js +2 -1
- package/dist/upsertRow/handleUpsertError.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +161 -48
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +2 -1
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/types.d.ts +3 -0
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.js +7 -18
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.js +13 -9
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts +15 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts.map +1 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +110 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -0
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +10 -12
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.js +1 -1
- package/dist/utilities/executeSchemaHooks.js.map +1 -1
- package/dist/utilities/formatGeneratedFile.d.ts +10 -0
- package/dist/utilities/formatGeneratedFile.d.ts.map +1 -0
- package/dist/utilities/formatGeneratedFile.js +58 -0
- package/dist/utilities/formatGeneratedFile.js.map +1 -0
- package/dist/utilities/getPrimaryDb.d.ts +1 -1
- package/dist/utilities/getSizesToVariantsRenames.d.ts +54 -0
- package/dist/utilities/getSizesToVariantsRenames.d.ts.map +1 -0
- package/dist/utilities/getSizesToVariantsRenames.js +252 -0
- package/dist/utilities/getSizesToVariantsRenames.js.map +1 -0
- package/dist/utilities/getTransaction.d.ts +1 -1
- package/dist/utilities/getTransaction.d.ts.map +1 -1
- package/dist/utilities/getTransaction.js.map +1 -1
- package/dist/utilities/parseJSONPathSegment.d.ts +9 -0
- package/dist/utilities/parseJSONPathSegment.d.ts.map +1 -0
- package/dist/utilities/parseJSONPathSegment.js +17 -0
- package/dist/utilities/parseJSONPathSegment.js.map +1 -0
- package/dist/utilities/pushDevSchema.js +1 -1
- package/dist/utilities/pushDevSchema.js.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +1 -5
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/utilities/validateIdentifierLength.d.ts +12 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -0
- package/dist/utilities/validateIdentifierLength.js +18 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -0
- package/package.json +19 -26
- package/dist/exports/types-deprecated.d.ts +0 -150
- package/dist/exports/types-deprecated.d.ts.map +0 -1
- package/dist/exports/types-deprecated.js +0 -5
- package/dist/exports/types-deprecated.js.map +0 -1
- package/dist/find/chainMethods.d.ts +0 -20
- package/dist/find/chainMethods.d.ts.map +0 -1
- package/dist/find/chainMethods.js +0 -16
- package/dist/find/chainMethods.js.map +0 -1
- package/dist/sqlite/requireDrizzleKit.d.ts +0 -3
- package/dist/sqlite/requireDrizzleKit.d.ts.map +0 -1
- package/dist/sqlite/requireDrizzleKit.js +0 -12
- package/dist/sqlite/requireDrizzleKit.js.map +0 -1
- package/dist/utilities/isValidStringID.spec.js +0 -15
- package/dist/utilities/isValidStringID.spec.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { and, eq, getTableName, like, sql } from 'drizzle-orm';
|
|
2
|
-
import { APIError, getFieldByPath } from 'payload';
|
|
1
|
+
import { and, eq, getTableName, isNull, like, notInArray, or, sql } from 'drizzle-orm';
|
|
2
|
+
import { APIError, getBranchPredicateSync, getFieldByPath, resolveBranchReadState } from 'payload';
|
|
3
3
|
import { fieldShouldBeLocalized, tabHasName } from 'payload/shared';
|
|
4
4
|
import toSnakeCase from 'to-snake-case';
|
|
5
5
|
import { validate as uuidValidate } from 'uuid';
|
|
@@ -9,20 +9,98 @@ import { jsonBuildObject } from '../utilities/json.js';
|
|
|
9
9
|
import { DistinctSymbol } from '../utilities/rawConstraint.js';
|
|
10
10
|
import { resolveBlockTableName } from '../utilities/validateExistingBlockIsIdentical.js';
|
|
11
11
|
import { addJoinTable } from './addJoinTable.js';
|
|
12
|
+
import { buildBranchVisibility } from './buildBranchVisibility.js';
|
|
12
13
|
import { getTableAlias } from './getTableAlias.js';
|
|
14
|
+
import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRelationshipPath.js';
|
|
15
|
+
const getRelationshipJoinCondition = ({ adapter, collectionSlug, relationshipID, req, table, value })=>{
|
|
16
|
+
const branchReadState = resolveBranchReadState({
|
|
17
|
+
collectionSlug,
|
|
18
|
+
req
|
|
19
|
+
});
|
|
20
|
+
const branchPredicate = branchReadState.useBranching ? null : getBranchPredicateSync({
|
|
21
|
+
collectionSlug,
|
|
22
|
+
req
|
|
23
|
+
});
|
|
24
|
+
const shouldMatchCanonicalID = Boolean(table._branchDocID && (branchReadState.useBranching || branchPredicate || value === DistinctSymbol));
|
|
25
|
+
const identityCondition = shouldMatchCanonicalID ? or(eq(table.id, relationshipID), eq(table._branchDocID, relationshipID)) : eq(table.id, relationshipID);
|
|
26
|
+
const branchCondition = getBranchTableCondition({
|
|
27
|
+
adapter,
|
|
28
|
+
collectionSlug,
|
|
29
|
+
req,
|
|
30
|
+
table
|
|
31
|
+
});
|
|
32
|
+
return branchCondition ? and(identityCondition, branchCondition) : identityCondition;
|
|
33
|
+
};
|
|
34
|
+
const getBranchTableCondition = ({ adapter, collectionSlug, req, table })=>{
|
|
35
|
+
const branchReadState = resolveBranchReadState({
|
|
36
|
+
collectionSlug,
|
|
37
|
+
req
|
|
38
|
+
});
|
|
39
|
+
if (branchReadState.useBranching) {
|
|
40
|
+
return buildBranchVisibility({
|
|
41
|
+
adapter,
|
|
42
|
+
branch: branchReadState.branch,
|
|
43
|
+
collectionSlug,
|
|
44
|
+
table
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const branchPredicate = getBranchPredicateSync({
|
|
48
|
+
collectionSlug,
|
|
49
|
+
req
|
|
50
|
+
});
|
|
51
|
+
return branchPredicate ? buildBranchPredicateCondition({
|
|
52
|
+
table,
|
|
53
|
+
where: branchPredicate
|
|
54
|
+
}) : undefined;
|
|
55
|
+
};
|
|
56
|
+
const buildBranchPredicateCondition = ({ table, where })=>{
|
|
57
|
+
const conditions = [];
|
|
58
|
+
for (const [fieldName, condition] of Object.entries(where)){
|
|
59
|
+
if ((fieldName === 'and' || fieldName === 'or') && Array.isArray(condition)) {
|
|
60
|
+
const nestedConditions = condition.map((nestedWhere)=>buildBranchPredicateCondition({
|
|
61
|
+
table,
|
|
62
|
+
where: nestedWhere
|
|
63
|
+
})).filter((nestedCondition)=>Boolean(nestedCondition));
|
|
64
|
+
const nestedResult = fieldName === 'and' ? and(...nestedConditions) : or(...nestedConditions);
|
|
65
|
+
if (nestedResult) {
|
|
66
|
+
conditions.push(nestedResult);
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const column = table[fieldName];
|
|
71
|
+
if (!column || !condition || typeof condition !== 'object') {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if ('equals' in condition) {
|
|
75
|
+
conditions.push(condition.equals === null ? isNull(column) : eq(column, condition.equals));
|
|
76
|
+
}
|
|
77
|
+
if ('not_in' in condition && Array.isArray(condition.not_in) && condition.not_in.length > 0) {
|
|
78
|
+
conditions.push(notInArray(column, condition.not_in));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return conditions.length === 1 ? conditions[0] : and(...conditions);
|
|
82
|
+
};
|
|
13
83
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
84
|
+
* Resolves a field path to the database table and column that store its value.
|
|
85
|
+
*
|
|
86
|
+
* While walking through relationships, arrays, and blocks, the function adds the joins required
|
|
87
|
+
* to reach the final column. Table aliases are used when the path is resolved inside a subquery.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* Resolving `movies.name` adds joins from the parent collection to its relationship table and then
|
|
91
|
+
* to the `movies` table. The returned column is `movies.name`.
|
|
92
|
+
*
|
|
93
|
+
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
94
|
+
*/ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, req, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix = '', value })=>{
|
|
18
95
|
const fieldPath = incomingSegments[0];
|
|
19
96
|
let locale = incomingLocale;
|
|
20
97
|
const rootTableName = incomingRootTableName || tableName;
|
|
98
|
+
const tableContainingField = parentAliasTable ?? aliasTable ?? adapter.tables[rootTableName];
|
|
21
99
|
let constraintPath = incomingConstraintPath || '';
|
|
22
100
|
const field = fields.find((fieldToFind)=>fieldToFind.name === fieldPath);
|
|
23
101
|
let newTableName = tableName;
|
|
24
102
|
if (!field && fieldPath === 'id') {
|
|
25
|
-
|
|
103
|
+
const idTable = aliasTable ?? adapter.tables[newTableName];
|
|
26
104
|
return {
|
|
27
105
|
columnName: 'id',
|
|
28
106
|
constraints,
|
|
@@ -30,7 +108,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
30
108
|
name: 'id',
|
|
31
109
|
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
32
110
|
},
|
|
33
|
-
table:
|
|
111
|
+
table: idTable
|
|
34
112
|
};
|
|
35
113
|
}
|
|
36
114
|
let localizedPathQuery = false;
|
|
@@ -38,6 +116,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
38
116
|
const pathSegments = [
|
|
39
117
|
...incomingSegments
|
|
40
118
|
];
|
|
119
|
+
const fieldStoragePath = appendFieldToStoragePath({
|
|
120
|
+
field,
|
|
121
|
+
path: constraintPath
|
|
122
|
+
});
|
|
41
123
|
const isFieldLocalized = fieldShouldBeLocalized({
|
|
42
124
|
field,
|
|
43
125
|
parentIsLocalized
|
|
@@ -57,7 +139,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
57
139
|
{
|
|
58
140
|
newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
|
|
59
141
|
const arrayParentTable = aliasTable || adapter.tables[tableName];
|
|
60
|
-
constraintPath = `${
|
|
142
|
+
constraintPath = `${fieldStoragePath}.`;
|
|
61
143
|
if (locale && isFieldLocalized && adapter.payload.config.localization) {
|
|
62
144
|
const conditions = [
|
|
63
145
|
eq(arrayParentTable.id, adapter.tables[newTableName]._parentID)
|
|
@@ -93,6 +175,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
93
175
|
parentAliasTable: aliasTable,
|
|
94
176
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
95
177
|
pathSegments: pathSegments.slice(1),
|
|
178
|
+
req,
|
|
96
179
|
rootTableName,
|
|
97
180
|
selectFields,
|
|
98
181
|
selectLocale,
|
|
@@ -114,7 +197,12 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
114
197
|
value
|
|
115
198
|
];
|
|
116
199
|
blockTypes.forEach((blockType)=>{
|
|
117
|
-
const
|
|
200
|
+
const fieldBlock = field.blocks.find((block)=>typeof block === 'string' ? block === blockType : block.slug === blockType);
|
|
201
|
+
const registeredBlocks = adapter.payload.blocks;
|
|
202
|
+
const block = typeof fieldBlock === 'string' ? registeredBlocks[fieldBlock] : fieldBlock;
|
|
203
|
+
if (!block) {
|
|
204
|
+
throw new APIError('Block was not found', 400);
|
|
205
|
+
}
|
|
118
206
|
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
119
207
|
const { newAliasTable } = getTableAlias({
|
|
120
208
|
adapter,
|
|
@@ -137,10 +225,9 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
137
225
|
table: adapter.tables[tableName]
|
|
138
226
|
};
|
|
139
227
|
}
|
|
140
|
-
const hasBlockField =
|
|
228
|
+
const hasBlockField = field.blocks.some((_block)=>{
|
|
141
229
|
const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block;
|
|
142
230
|
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
143
|
-
constraintPath = `${constraintPath}${field.name}.%.`;
|
|
144
231
|
let result;
|
|
145
232
|
const blockConstraints = [];
|
|
146
233
|
const blockSelectFields = {};
|
|
@@ -170,13 +257,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
170
257
|
result = getTableColumnFromPath({
|
|
171
258
|
adapter,
|
|
172
259
|
collectionPath,
|
|
173
|
-
constraintPath
|
|
260
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
174
261
|
constraints: blockConstraints,
|
|
175
262
|
fields: block.flattenedFields,
|
|
176
263
|
joins: newJoins,
|
|
177
264
|
locale,
|
|
178
265
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
179
266
|
pathSegments: pathSegments.slice(1),
|
|
267
|
+
req,
|
|
180
268
|
rootTableName,
|
|
181
269
|
selectFields: blockSelectFields,
|
|
182
270
|
selectLocale,
|
|
@@ -236,13 +324,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
236
324
|
aliasTable,
|
|
237
325
|
collectionPath,
|
|
238
326
|
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
239
|
-
constraintPath: `${
|
|
327
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
240
328
|
constraints,
|
|
241
329
|
fields: field.flattenedFields,
|
|
242
330
|
joins,
|
|
243
331
|
locale,
|
|
244
332
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
245
333
|
pathSegments: pathSegments.slice(1),
|
|
334
|
+
req,
|
|
246
335
|
rootTableName,
|
|
247
336
|
selectFields,
|
|
248
337
|
selectLocale,
|
|
@@ -257,6 +346,15 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
257
346
|
throw new APIError('Not supported');
|
|
258
347
|
}
|
|
259
348
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
349
|
+
// Filtering through a polymorphic `on` relationship is not supported: it is stored in the
|
|
350
|
+
// `_rels` table with no direct column to correlate on, which would otherwise build invalid SQL.
|
|
351
|
+
const onRelationshipField = getFieldByPath({
|
|
352
|
+
fields: adapter.payload.collections[field.collection].config.flattenedFields,
|
|
353
|
+
path: field.on
|
|
354
|
+
})?.field;
|
|
355
|
+
if (onRelationshipField && (onRelationshipField.type === 'relationship' || onRelationshipField.type === 'upload') && Array.isArray(onRelationshipField.relationTo)) {
|
|
356
|
+
throw new APIError('Not supported');
|
|
357
|
+
}
|
|
260
358
|
if (field.hasMany) {
|
|
261
359
|
const relationTableName = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${adapter.relationshipsSuffix}`;
|
|
262
360
|
const existingTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}._rels`);
|
|
@@ -273,7 +371,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
273
371
|
}
|
|
274
372
|
if (!existingTable) {
|
|
275
373
|
addJoinTable({
|
|
276
|
-
condition: and(eq(
|
|
374
|
+
condition: and(eq(tableContainingField.id, aliasRelationshipTable[`${relationshipField.field.relationTo}ID`]), like(aliasRelationshipTable.path, field.on)),
|
|
277
375
|
joins,
|
|
278
376
|
queryPath: `${constraintPath}${field.name}._rels`,
|
|
279
377
|
table: aliasRelationshipTable
|
|
@@ -300,8 +398,15 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
300
398
|
tableName: relationshipTableName
|
|
301
399
|
}).newAliasTable;
|
|
302
400
|
if (!existingMainTable) {
|
|
401
|
+
const branchCondition = getBranchTableCondition({
|
|
402
|
+
adapter,
|
|
403
|
+
collectionSlug: field.collection,
|
|
404
|
+
req,
|
|
405
|
+
table: relationshipTable
|
|
406
|
+
});
|
|
407
|
+
const relationshipCondition = eq(aliasRelationshipTable.parent, relationshipTable.id);
|
|
303
408
|
joins.push({
|
|
304
|
-
condition:
|
|
409
|
+
condition: branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition,
|
|
305
410
|
queryPath: `${constraintPath}${field.name}`,
|
|
306
411
|
table: relationshipTable
|
|
307
412
|
});
|
|
@@ -311,12 +416,13 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
311
416
|
aliasTable: relationshipTable,
|
|
312
417
|
collectionPath: newCollectionPath,
|
|
313
418
|
constraints,
|
|
314
|
-
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
315
419
|
fields: relationshipFields,
|
|
316
420
|
joins,
|
|
317
421
|
locale,
|
|
422
|
+
// A join reads from a different collection, so localization does not carry over
|
|
318
423
|
parentIsLocalized: false,
|
|
319
424
|
pathSegments: pathSegments.slice(1),
|
|
425
|
+
req,
|
|
320
426
|
rootTableName: relationshipTableName,
|
|
321
427
|
selectFields,
|
|
322
428
|
selectLocale,
|
|
@@ -347,13 +453,29 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
347
453
|
table: arrayAliasTable
|
|
348
454
|
});
|
|
349
455
|
joins.push({
|
|
350
|
-
condition:
|
|
456
|
+
condition: (()=>{
|
|
457
|
+
const relationshipCondition = eq(newAliasTable['id'], arrayAliasTable._parentID);
|
|
458
|
+
const branchCondition = getBranchTableCondition({
|
|
459
|
+
adapter,
|
|
460
|
+
collectionSlug: field.collection,
|
|
461
|
+
req,
|
|
462
|
+
table: newAliasTable
|
|
463
|
+
});
|
|
464
|
+
return branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition;
|
|
465
|
+
})(),
|
|
351
466
|
queryPath: `${constraintPath}${field.name}`,
|
|
352
467
|
table: newAliasTable
|
|
353
468
|
});
|
|
354
469
|
} else {
|
|
470
|
+
const relationshipCondition = eq(newAliasTable[field.on.replaceAll('.', '_')], aliasTable ? aliasTable.id : adapter.tables[tableName].id);
|
|
471
|
+
const branchCondition = getBranchTableCondition({
|
|
472
|
+
adapter,
|
|
473
|
+
collectionSlug: field.collection,
|
|
474
|
+
req,
|
|
475
|
+
table: newAliasTable
|
|
476
|
+
});
|
|
355
477
|
joins.push({
|
|
356
|
-
condition:
|
|
478
|
+
condition: branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition,
|
|
357
479
|
queryPath: `${constraintPath}${field.name}`,
|
|
358
480
|
table: newAliasTable
|
|
359
481
|
});
|
|
@@ -379,8 +501,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
379
501
|
fields: adapter.payload.collections[field.collection].config.flattenedFields,
|
|
380
502
|
joins,
|
|
381
503
|
locale,
|
|
382
|
-
|
|
504
|
+
// A join reads from a different collection, so localization does not carry over
|
|
505
|
+
parentIsLocalized: false,
|
|
383
506
|
pathSegments: pathSegments.slice(1),
|
|
507
|
+
req,
|
|
384
508
|
selectFields,
|
|
385
509
|
tableName: newTableName,
|
|
386
510
|
value
|
|
@@ -398,14 +522,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
398
522
|
columnName = 'number';
|
|
399
523
|
}
|
|
400
524
|
newTableName = `${rootTableName}_${tableType}`;
|
|
401
|
-
const existingTable = joins.find((e)=>e.queryPath ===
|
|
525
|
+
const existingTable = joins.find((e)=>e.queryPath === fieldStoragePath);
|
|
402
526
|
const table = existingTable?.table ?? getTableAlias({
|
|
403
527
|
adapter,
|
|
404
528
|
tableName: newTableName
|
|
405
529
|
}).newAliasTable;
|
|
406
530
|
const joinConstraints = [
|
|
407
|
-
eq(
|
|
408
|
-
like(table.path,
|
|
531
|
+
eq(tableContainingField.id, table.parent),
|
|
532
|
+
like(table.path, fieldStoragePath)
|
|
409
533
|
];
|
|
410
534
|
if (locale && isFieldLocalized && adapter.payload.config.localization) {
|
|
411
535
|
const conditions = [
|
|
@@ -417,14 +541,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
417
541
|
addJoinTable({
|
|
418
542
|
condition: and(...conditions),
|
|
419
543
|
joins,
|
|
420
|
-
queryPath:
|
|
544
|
+
queryPath: fieldStoragePath,
|
|
421
545
|
table
|
|
422
546
|
});
|
|
423
547
|
} else {
|
|
424
548
|
addJoinTable({
|
|
425
549
|
condition: and(...joinConstraints),
|
|
426
550
|
joins,
|
|
427
|
-
queryPath:
|
|
551
|
+
queryPath: fieldStoragePath,
|
|
428
552
|
table
|
|
429
553
|
});
|
|
430
554
|
}
|
|
@@ -441,10 +565,23 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
441
565
|
case 'upload':
|
|
442
566
|
{
|
|
443
567
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
568
|
+
const relationshipQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._rels`;
|
|
569
|
+
const targetQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._target${isFieldLocalized && locale ? `.${locale}` : ''}`;
|
|
444
570
|
if (Array.isArray(field.relationTo) || field.hasMany) {
|
|
571
|
+
const relationshipPath = resolveRelationshipPath({
|
|
572
|
+
adapter,
|
|
573
|
+
fields,
|
|
574
|
+
locale,
|
|
575
|
+
parentIsLocalized,
|
|
576
|
+
path: field.name,
|
|
577
|
+
pathPrefix: constraintPath
|
|
578
|
+
});
|
|
579
|
+
if (!relationshipPath) {
|
|
580
|
+
throw new APIError(`Relationship path could not be resolved: ${collectionPath}`);
|
|
581
|
+
}
|
|
445
582
|
let relationshipFields;
|
|
446
583
|
const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
|
|
447
|
-
const existingJoin = joins.find((e)=>e.queryPath ===
|
|
584
|
+
const existingJoin = joins.find((e)=>e.queryPath === relationshipQueryPath);
|
|
448
585
|
let aliasRelationshipTable;
|
|
449
586
|
let aliasRelationshipTableName;
|
|
450
587
|
if (existingJoin) {
|
|
@@ -458,30 +595,28 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
458
595
|
aliasRelationshipTable = res.newAliasTable;
|
|
459
596
|
aliasRelationshipTableName = res.newAliasTableName;
|
|
460
597
|
}
|
|
461
|
-
if (selectLocale &&
|
|
598
|
+
if (selectLocale && relationshipPath.isLocalized && adapter.payload.config.localization) {
|
|
462
599
|
selectFields._locale = aliasRelationshipTable.locale;
|
|
463
600
|
}
|
|
464
601
|
// Join in the relationships table
|
|
465
|
-
if (locale &&
|
|
602
|
+
if (relationshipPath.locale && relationshipPath.locale !== 'all' && relationshipPath.isLocalized && adapter.payload.config.localization) {
|
|
466
603
|
const conditions = [
|
|
467
|
-
eq(
|
|
468
|
-
like(aliasRelationshipTable.path,
|
|
604
|
+
eq(tableContainingField.id, aliasRelationshipTable.parent),
|
|
605
|
+
like(aliasRelationshipTable.path, relationshipPath.path)
|
|
469
606
|
];
|
|
470
|
-
|
|
471
|
-
conditions.push(eq(aliasRelationshipTable.locale, locale));
|
|
472
|
-
}
|
|
607
|
+
conditions.push(eq(aliasRelationshipTable.locale, relationshipPath.locale));
|
|
473
608
|
addJoinTable({
|
|
474
609
|
condition: and(...conditions),
|
|
475
610
|
joins,
|
|
476
|
-
queryPath:
|
|
611
|
+
queryPath: relationshipQueryPath,
|
|
477
612
|
table: aliasRelationshipTable
|
|
478
613
|
});
|
|
479
614
|
} else {
|
|
480
615
|
// Join in the relationships table
|
|
481
616
|
addJoinTable({
|
|
482
|
-
condition: and(eq(
|
|
617
|
+
condition: and(eq(tableContainingField.id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, relationshipPath.path)),
|
|
483
618
|
joins,
|
|
484
|
-
queryPath:
|
|
619
|
+
queryPath: relationshipQueryPath,
|
|
485
620
|
table: aliasRelationshipTable
|
|
486
621
|
});
|
|
487
622
|
}
|
|
@@ -492,15 +627,31 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
492
627
|
newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
|
|
493
628
|
// parent to relationship join table
|
|
494
629
|
relationshipFields = relationshipConfig.flattenedFields;
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
630
|
+
const existingTargetJoin = joins.find((join)=>join.queryPath === targetQueryPath);
|
|
631
|
+
if (existingTargetJoin) {
|
|
632
|
+
newAliasTable = existingTargetJoin.table;
|
|
633
|
+
} else {
|
|
634
|
+
;
|
|
635
|
+
({ newAliasTable } = getTableAlias({
|
|
636
|
+
adapter,
|
|
637
|
+
tableName: newTableName
|
|
638
|
+
}));
|
|
639
|
+
const relationshipID = aliasRelationshipTable[`${field.relationTo}ID`];
|
|
640
|
+
const condition = getRelationshipJoinCondition({
|
|
641
|
+
adapter,
|
|
642
|
+
collectionSlug: field.relationTo,
|
|
643
|
+
relationshipID,
|
|
644
|
+
req,
|
|
645
|
+
table: newAliasTable,
|
|
646
|
+
value
|
|
647
|
+
});
|
|
648
|
+
joins.push({
|
|
649
|
+
condition,
|
|
650
|
+
queryPath: targetQueryPath,
|
|
651
|
+
table: newAliasTable
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
if (newCollectionPath === '' || newCollectionPath === 'id' && !existingTargetJoin) {
|
|
504
655
|
return {
|
|
505
656
|
columnName: `${field.relationTo}ID`,
|
|
506
657
|
constraints,
|
|
@@ -597,33 +748,35 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
597
748
|
aliasTable: newAliasTable,
|
|
598
749
|
collectionPath: newCollectionPath,
|
|
599
750
|
constraints,
|
|
600
|
-
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
601
751
|
fields: relationshipFields,
|
|
602
752
|
joins,
|
|
603
753
|
locale,
|
|
754
|
+
// A relationship jumps to a different collection, so localization does not carry over
|
|
604
755
|
parentIsLocalized: false,
|
|
605
756
|
pathSegments: pathSegments.slice(1),
|
|
757
|
+
req,
|
|
606
758
|
rootTableName: newTableName,
|
|
607
759
|
selectFields,
|
|
608
760
|
selectLocale,
|
|
609
761
|
tableName: newTableName,
|
|
610
762
|
value
|
|
611
763
|
});
|
|
612
|
-
} else if (pathSegments.length > 1 && !(pathSegments.length === 2 && pathSegments[1] === 'id')) {
|
|
764
|
+
} else if (pathSegments.length > 1 && (!(pathSegments.length === 2 && pathSegments[1] === 'id') || joins.some((join)=>join.queryPath === targetQueryPath))) {
|
|
613
765
|
// simple relationships
|
|
614
766
|
const columnName = `${columnPrefix}${field.name}`;
|
|
615
767
|
const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[field.relationTo].config.slug));
|
|
616
|
-
const
|
|
768
|
+
const existingTargetJoin = joins.find((join)=>join.queryPath === targetQueryPath);
|
|
769
|
+
const newAliasTable = existingTargetJoin?.table ?? getTableAlias({
|
|
617
770
|
adapter,
|
|
618
771
|
tableName: newTableName
|
|
619
|
-
});
|
|
620
|
-
if (isFieldLocalized && adapter.payload.config.localization) {
|
|
772
|
+
}).newAliasTable;
|
|
773
|
+
if (!existingTargetJoin && isFieldLocalized && adapter.payload.config.localization) {
|
|
621
774
|
const { newAliasTable: aliasLocaleTable } = getTableAlias({
|
|
622
775
|
adapter,
|
|
623
776
|
tableName: `${rootTableName}${adapter.localesSuffix}`
|
|
624
777
|
});
|
|
625
778
|
const condtions = [
|
|
626
|
-
eq(aliasLocaleTable._parentID,
|
|
779
|
+
eq(aliasLocaleTable._parentID, tableContainingField.id)
|
|
627
780
|
];
|
|
628
781
|
if (selectLocale) {
|
|
629
782
|
selectFields._locale = aliasLocaleTable._locale;
|
|
@@ -631,19 +784,37 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
631
784
|
if (locale !== 'all') {
|
|
632
785
|
condtions.push(eq(aliasLocaleTable._locale, locale));
|
|
633
786
|
}
|
|
634
|
-
const localesTable = adapter.tables[`${rootTableName}${adapter.localesSuffix}`];
|
|
635
787
|
addJoinTable({
|
|
636
788
|
condition: and(...condtions),
|
|
637
789
|
joins,
|
|
638
|
-
table:
|
|
790
|
+
table: aliasLocaleTable
|
|
791
|
+
});
|
|
792
|
+
const condition = getRelationshipJoinCondition({
|
|
793
|
+
adapter,
|
|
794
|
+
collectionSlug: field.relationTo,
|
|
795
|
+
relationshipID: aliasLocaleTable[columnName],
|
|
796
|
+
req,
|
|
797
|
+
table: newAliasTable,
|
|
798
|
+
value
|
|
639
799
|
});
|
|
640
800
|
joins.push({
|
|
641
|
-
condition
|
|
801
|
+
condition,
|
|
802
|
+
queryPath: targetQueryPath,
|
|
642
803
|
table: newAliasTable
|
|
643
804
|
});
|
|
644
|
-
} else {
|
|
805
|
+
} else if (!existingTargetJoin) {
|
|
806
|
+
const relationshipID = aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName];
|
|
807
|
+
const condition = getRelationshipJoinCondition({
|
|
808
|
+
adapter,
|
|
809
|
+
collectionSlug: field.relationTo,
|
|
810
|
+
relationshipID,
|
|
811
|
+
req,
|
|
812
|
+
table: newAliasTable,
|
|
813
|
+
value
|
|
814
|
+
});
|
|
645
815
|
joins.push({
|
|
646
|
-
condition
|
|
816
|
+
condition,
|
|
817
|
+
queryPath: targetQueryPath,
|
|
647
818
|
table: newAliasTable
|
|
648
819
|
});
|
|
649
820
|
}
|
|
@@ -656,8 +827,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
656
827
|
fields: adapter.payload.collections[field.relationTo].config.flattenedFields,
|
|
657
828
|
joins,
|
|
658
829
|
locale,
|
|
659
|
-
|
|
830
|
+
// A relationship jumps to a different collection, so localization does not carry over
|
|
831
|
+
parentIsLocalized: false,
|
|
660
832
|
pathSegments: pathSegments.slice(1),
|
|
833
|
+
req,
|
|
661
834
|
selectFields,
|
|
662
835
|
tableName: newTableName,
|
|
663
836
|
value
|
|
@@ -707,13 +880,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
707
880
|
aliasTable,
|
|
708
881
|
collectionPath,
|
|
709
882
|
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
710
|
-
constraintPath: `${
|
|
883
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
711
884
|
constraints,
|
|
712
885
|
fields: field.flattenedFields,
|
|
713
886
|
joins,
|
|
714
887
|
locale,
|
|
715
888
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
716
889
|
pathSegments: pathSegments.slice(1),
|
|
890
|
+
req,
|
|
717
891
|
rootTableName,
|
|
718
892
|
selectFields,
|
|
719
893
|
selectLocale,
|
|
@@ -734,6 +908,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
734
908
|
locale,
|
|
735
909
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
736
910
|
pathSegments: pathSegments.slice(1),
|
|
911
|
+
req,
|
|
737
912
|
rootTableName,
|
|
738
913
|
selectFields,
|
|
739
914
|
selectLocale,
|