@payloadcms/drizzle 4.0.0-internal.934870d → 4.0.0-internal.94ef095
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/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/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 +1 -1
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +1 -1
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +1 -1
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +1 -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 +5 -3
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.js +43 -15
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -1
- package/dist/find/buildPolymorphicJoinWhere.js +1 -1
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -1
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +2 -1
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -1
- package/dist/find/createPolymorphicJoinWherePlan.js +14 -5
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -1
- 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 +64 -8
- 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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.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/v2-v3/index.js +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- 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/types.d.ts +4 -0
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +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.map +1 -1
- package/dist/queries/buildOperatorConstraint.js +16 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +3 -2
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +2 -1
- 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 +3 -2
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +173 -30
- package/dist/queries/getTableColumnFromPath.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 +4 -1
- package/dist/queries/parseParams.js.map +1 -1
- 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/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 +6 -3
- package/dist/schema/traverseFields.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 +5 -3
- package/dist/sqlite/insert.js.map +1 -1
- 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 +44 -8
- 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 +3 -2
- package/dist/types.d.ts.map +1 -1
- 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/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +55 -5
- 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/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +132 -42
- package/dist/upsertRow/index.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.js +1 -1
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +1 -1
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -1
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +7 -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/getSizesToVariantsRenames.d.ts.map +1 -1
- package/dist/utilities/getSizesToVariantsRenames.js +1 -0
- package/dist/utilities/getSizesToVariantsRenames.js.map +1 -1
- package/dist/utilities/getTransaction.js.map +1 -1
- package/dist/utilities/pushDevSchema.js +1 -1
- package/dist/utilities/pushDevSchema.js.map +1 -1
- package/package.json +17 -19
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { buildOrderBy } from './buildOrderBy.js';
|
|
2
2
|
import { parseParams } from './parseParams.js';
|
|
3
|
-
export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joins = [], locale, parentIsLocalized, selectLocale, sort, tableName, where: incomingWhere }) {
|
|
3
|
+
export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joins = [], locale, parentIsLocalized, req, selectLocale, sort, tableName, where: incomingWhere }) {
|
|
4
4
|
const selectFields = {
|
|
5
|
-
id: adapter.tables[tableName]
|
|
5
|
+
id: (aliasTable ?? adapter.tables[tableName])['id']
|
|
6
6
|
};
|
|
7
7
|
let where;
|
|
8
8
|
const context = {
|
|
@@ -17,6 +17,7 @@ export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joi
|
|
|
17
17
|
joins,
|
|
18
18
|
locale,
|
|
19
19
|
parentIsLocalized,
|
|
20
|
+
req,
|
|
20
21
|
selectFields,
|
|
21
22
|
selectLocale,
|
|
22
23
|
tableName,
|
|
@@ -31,6 +32,7 @@ export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joi
|
|
|
31
32
|
locale,
|
|
32
33
|
parentIsLocalized,
|
|
33
34
|
rawSort: context.rawSort,
|
|
35
|
+
req,
|
|
34
36
|
selectFields,
|
|
35
37
|
sort: context.sort,
|
|
36
38
|
tableName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { asc, desc, SQL, Table } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { FlattenedField, Sort, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js'\nimport type { QueryContext } from './parseParams.js'\n\nimport { buildOrderBy } from './buildOrderBy.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n // with parent\n isOneToMany?: boolean\n queryPath?: string\n table: GenericTable | PgTableWithColumns<any>\n type?: 'innerJoin' | 'leftJoin' | 'rightJoin'\n}[]\n\ntype BuildQueryArgs = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n joins?: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized?: boolean\n selectLocale?: boolean\n sort?: Sort\n tableName: string\n where: Where\n}\n\nexport type BuildQueryResult = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }[]\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\n\nexport const buildQuery = function buildQuery({\n adapter,\n aliasTable,\n fields,\n joins = [],\n locale,\n parentIsLocalized,\n selectLocale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): BuildQueryResult {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName]
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { asc, desc, SQL, Table } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { FlattenedField, PayloadRequest, Sort, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js'\nimport type { QueryContext } from './parseParams.js'\n\nimport { buildOrderBy } from './buildOrderBy.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n // with parent\n isOneToMany?: boolean\n queryPath?: string\n table: GenericTable | PgTableWithColumns<any>\n type?: 'innerJoin' | 'leftJoin' | 'rightJoin'\n}[]\n\ntype BuildQueryArgs = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n joins?: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized?: boolean\n req?: Partial<PayloadRequest>\n selectLocale?: boolean\n sort?: Sort\n tableName: string\n where: Where\n}\n\nexport type BuildQueryResult = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }[]\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\n\nexport const buildQuery = function buildQuery({\n adapter,\n aliasTable,\n fields,\n joins = [],\n locale,\n parentIsLocalized,\n req,\n selectLocale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): BuildQueryResult {\n const selectFields: Record<string, GenericColumn> = {\n id: (aliasTable ?? adapter.tables[tableName])['id'],\n }\n\n let where: SQL\n\n const context: QueryContext = { sort }\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n req,\n selectFields,\n selectLocale,\n tableName,\n where: incomingWhere,\n })\n }\n\n const orderBy = buildOrderBy({\n adapter,\n aliasTable,\n fields,\n joins,\n locale,\n parentIsLocalized,\n rawSort: context.rawSort,\n req,\n selectFields,\n sort: context.sort,\n tableName,\n })\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n"],"names":["buildOrderBy","parseParams","buildQuery","adapter","aliasTable","fields","joins","locale","parentIsLocalized","req","selectLocale","sort","tableName","where","incomingWhere","selectFields","id","tables","context","Object","keys","length","orderBy","rawSort"],"mappings":"AAOA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AAmC9C,OAAO,MAAMC,aAAa,SAASA,WAAW,EAC5CC,OAAO,EACPC,UAAU,EACVC,MAAM,EACNC,QAAQ,EAAE,EACVC,MAAM,EACNC,iBAAiB,EACjBC,GAAG,EACHC,YAAY,EACZC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAI,AAACZ,CAAAA,cAAcD,QAAQc,MAAM,CAACL,UAAU,AAAD,CAAE,CAAC,KAAK;IACrD;IAEA,IAAIC;IAEJ,MAAMK,UAAwB;QAAEP;IAAK;IACrC,IAAIG,iBAAiBK,OAAOC,IAAI,CAACN,eAAeO,MAAM,GAAG,GAAG;QAC1DR,QAAQZ,YAAY;YAClBE;YACAC;YACAc;YACAb;YACAC;YACAC;YACAC;YACAC;YACAM;YACAL;YACAE;YACAC,OAAOC;QACT;IACF;IAEA,MAAMQ,UAAUtB,aAAa;QAC3BG;QACAC;QACAC;QACAC;QACAC;QACAC;QACAe,SAASL,QAAQK,OAAO;QACxBd;QACAM;QACAJ,MAAMO,QAAQP,IAAI;QAClBC;IACF;IAEA,OAAO;QACLN;QACAgB;QACAP;QACAF;IACF;AACF,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SQL } from 'drizzle-orm';
|
|
2
2
|
import type { SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
|
|
3
|
-
import type { FlattenedField } from 'payload';
|
|
3
|
+
import type { FlattenedField, PayloadRequest } from 'payload';
|
|
4
4
|
import { type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
5
5
|
import type { DrizzleAdapter, GenericColumn } from '../types.js';
|
|
6
6
|
import type { BuildQueryJoinAliases } from './buildQuery.js';
|
|
@@ -37,6 +37,7 @@ type Args = {
|
|
|
37
37
|
parentAliasTable?: PgTableWithColumns<any> | SQLiteTableWithColumns<any>;
|
|
38
38
|
parentIsLocalized: boolean;
|
|
39
39
|
pathSegments: string[];
|
|
40
|
+
req?: Partial<PayloadRequest>;
|
|
40
41
|
rootTableName?: string;
|
|
41
42
|
selectFields: Record<string, GenericColumn>;
|
|
42
43
|
selectLocale?: boolean;
|
|
@@ -62,6 +63,6 @@ type Args = {
|
|
|
62
63
|
*
|
|
63
64
|
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
64
65
|
*/
|
|
65
|
-
export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix, value, }: Args) => TableColumn;
|
|
66
|
+
export declare 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, }: Args) => TableColumn;
|
|
66
67
|
export {};
|
|
67
68
|
//# sourceMappingURL=getTableColumnFromPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAEV,cAAc,EAIf,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAM7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAEV,cAAc,EAEd,cAAc,EAIf,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAM7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAY5D,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAC5D,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,WAAW,GAAG;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;QAClC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;KACxB,EAAE,CAAA;IACH,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,KAAK,EAAE,cAAc,CAAA;IACrB,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,KAAK,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;CAC7D,CAAA;AAED,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,8FAA8F;IAC9F,UAAU,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAClE,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACxE,iBAAiB,EAAE,OAAO,CAAA;IAC1B,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAsGD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,sUAoBhC,IAAI,KAAG,WA4iCT,CAAA"}
|
|
@@ -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,8 +9,77 @@ 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';
|
|
13
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
|
+
};
|
|
14
83
|
/**
|
|
15
84
|
* Resolves a field path to the database table and column that store its value.
|
|
16
85
|
*
|
|
@@ -22,7 +91,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
22
91
|
* to the `movies` table. The returned column is `movies.name`.
|
|
23
92
|
*
|
|
24
93
|
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
25
|
-
*/ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix = '', value })=>{
|
|
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 })=>{
|
|
26
95
|
const fieldPath = incomingSegments[0];
|
|
27
96
|
let locale = incomingLocale;
|
|
28
97
|
const rootTableName = incomingRootTableName || tableName;
|
|
@@ -31,7 +100,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
31
100
|
const field = fields.find((fieldToFind)=>fieldToFind.name === fieldPath);
|
|
32
101
|
let newTableName = tableName;
|
|
33
102
|
if (!field && fieldPath === 'id') {
|
|
34
|
-
|
|
103
|
+
const idTable = aliasTable ?? adapter.tables[newTableName];
|
|
35
104
|
return {
|
|
36
105
|
columnName: 'id',
|
|
37
106
|
constraints,
|
|
@@ -39,7 +108,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
39
108
|
name: 'id',
|
|
40
109
|
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
41
110
|
},
|
|
42
|
-
table:
|
|
111
|
+
table: idTable
|
|
43
112
|
};
|
|
44
113
|
}
|
|
45
114
|
let localizedPathQuery = false;
|
|
@@ -106,6 +175,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
106
175
|
parentAliasTable: aliasTable,
|
|
107
176
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
108
177
|
pathSegments: pathSegments.slice(1),
|
|
178
|
+
req,
|
|
109
179
|
rootTableName,
|
|
110
180
|
selectFields,
|
|
111
181
|
selectLocale,
|
|
@@ -127,7 +197,12 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
127
197
|
value
|
|
128
198
|
];
|
|
129
199
|
blockTypes.forEach((blockType)=>{
|
|
130
|
-
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
|
+
}
|
|
131
206
|
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
132
207
|
const { newAliasTable } = getTableAlias({
|
|
133
208
|
adapter,
|
|
@@ -189,6 +264,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
189
264
|
locale,
|
|
190
265
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
191
266
|
pathSegments: pathSegments.slice(1),
|
|
267
|
+
req,
|
|
192
268
|
rootTableName,
|
|
193
269
|
selectFields: blockSelectFields,
|
|
194
270
|
selectLocale,
|
|
@@ -255,6 +331,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
255
331
|
locale,
|
|
256
332
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
257
333
|
pathSegments: pathSegments.slice(1),
|
|
334
|
+
req,
|
|
258
335
|
rootTableName,
|
|
259
336
|
selectFields,
|
|
260
337
|
selectLocale,
|
|
@@ -321,8 +398,15 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
321
398
|
tableName: relationshipTableName
|
|
322
399
|
}).newAliasTable;
|
|
323
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);
|
|
324
408
|
joins.push({
|
|
325
|
-
condition:
|
|
409
|
+
condition: branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition,
|
|
326
410
|
queryPath: `${constraintPath}${field.name}`,
|
|
327
411
|
table: relationshipTable
|
|
328
412
|
});
|
|
@@ -338,6 +422,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
338
422
|
// A join reads from a different collection, so localization does not carry over
|
|
339
423
|
parentIsLocalized: false,
|
|
340
424
|
pathSegments: pathSegments.slice(1),
|
|
425
|
+
req,
|
|
341
426
|
rootTableName: relationshipTableName,
|
|
342
427
|
selectFields,
|
|
343
428
|
selectLocale,
|
|
@@ -368,13 +453,29 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
368
453
|
table: arrayAliasTable
|
|
369
454
|
});
|
|
370
455
|
joins.push({
|
|
371
|
-
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
|
+
})(),
|
|
372
466
|
queryPath: `${constraintPath}${field.name}`,
|
|
373
467
|
table: newAliasTable
|
|
374
468
|
});
|
|
375
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
|
+
});
|
|
376
477
|
joins.push({
|
|
377
|
-
condition:
|
|
478
|
+
condition: branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition,
|
|
378
479
|
queryPath: `${constraintPath}${field.name}`,
|
|
379
480
|
table: newAliasTable
|
|
380
481
|
});
|
|
@@ -403,6 +504,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
403
504
|
// A join reads from a different collection, so localization does not carry over
|
|
404
505
|
parentIsLocalized: false,
|
|
405
506
|
pathSegments: pathSegments.slice(1),
|
|
507
|
+
req,
|
|
406
508
|
selectFields,
|
|
407
509
|
tableName: newTableName,
|
|
408
510
|
value
|
|
@@ -463,6 +565,8 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
463
565
|
case 'upload':
|
|
464
566
|
{
|
|
465
567
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
568
|
+
const relationshipQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._rels`;
|
|
569
|
+
const targetQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._target${isFieldLocalized && locale ? `.${locale}` : ''}`;
|
|
466
570
|
if (Array.isArray(field.relationTo) || field.hasMany) {
|
|
467
571
|
const relationshipPath = resolveRelationshipPath({
|
|
468
572
|
adapter,
|
|
@@ -477,7 +581,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
477
581
|
}
|
|
478
582
|
let relationshipFields;
|
|
479
583
|
const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
|
|
480
|
-
const existingJoin = joins.find((e)=>e.queryPath ===
|
|
584
|
+
const existingJoin = joins.find((e)=>e.queryPath === relationshipQueryPath);
|
|
481
585
|
let aliasRelationshipTable;
|
|
482
586
|
let aliasRelationshipTableName;
|
|
483
587
|
if (existingJoin) {
|
|
@@ -504,7 +608,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
504
608
|
addJoinTable({
|
|
505
609
|
condition: and(...conditions),
|
|
506
610
|
joins,
|
|
507
|
-
queryPath:
|
|
611
|
+
queryPath: relationshipQueryPath,
|
|
508
612
|
table: aliasRelationshipTable
|
|
509
613
|
});
|
|
510
614
|
} else {
|
|
@@ -512,7 +616,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
512
616
|
addJoinTable({
|
|
513
617
|
condition: and(eq(tableContainingField.id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, relationshipPath.path)),
|
|
514
618
|
joins,
|
|
515
|
-
queryPath:
|
|
619
|
+
queryPath: relationshipQueryPath,
|
|
516
620
|
table: aliasRelationshipTable
|
|
517
621
|
});
|
|
518
622
|
}
|
|
@@ -523,15 +627,31 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
523
627
|
newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
|
|
524
628
|
// parent to relationship join table
|
|
525
629
|
relationshipFields = relationshipConfig.flattenedFields;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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) {
|
|
535
655
|
return {
|
|
536
656
|
columnName: `${field.relationTo}ID`,
|
|
537
657
|
constraints,
|
|
@@ -634,21 +754,23 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
634
754
|
// A relationship jumps to a different collection, so localization does not carry over
|
|
635
755
|
parentIsLocalized: false,
|
|
636
756
|
pathSegments: pathSegments.slice(1),
|
|
757
|
+
req,
|
|
637
758
|
rootTableName: newTableName,
|
|
638
759
|
selectFields,
|
|
639
760
|
selectLocale,
|
|
640
761
|
tableName: newTableName,
|
|
641
762
|
value
|
|
642
763
|
});
|
|
643
|
-
} 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))) {
|
|
644
765
|
// simple relationships
|
|
645
766
|
const columnName = `${columnPrefix}${field.name}`;
|
|
646
767
|
const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[field.relationTo].config.slug));
|
|
647
|
-
const
|
|
768
|
+
const existingTargetJoin = joins.find((join)=>join.queryPath === targetQueryPath);
|
|
769
|
+
const newAliasTable = existingTargetJoin?.table ?? getTableAlias({
|
|
648
770
|
adapter,
|
|
649
771
|
tableName: newTableName
|
|
650
|
-
});
|
|
651
|
-
if (isFieldLocalized && adapter.payload.config.localization) {
|
|
772
|
+
}).newAliasTable;
|
|
773
|
+
if (!existingTargetJoin && isFieldLocalized && adapter.payload.config.localization) {
|
|
652
774
|
const { newAliasTable: aliasLocaleTable } = getTableAlias({
|
|
653
775
|
adapter,
|
|
654
776
|
tableName: `${rootTableName}${adapter.localesSuffix}`
|
|
@@ -662,19 +784,37 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
662
784
|
if (locale !== 'all') {
|
|
663
785
|
condtions.push(eq(aliasLocaleTable._locale, locale));
|
|
664
786
|
}
|
|
665
|
-
const localesTable = adapter.tables[`${rootTableName}${adapter.localesSuffix}`];
|
|
666
787
|
addJoinTable({
|
|
667
788
|
condition: and(...condtions),
|
|
668
789
|
joins,
|
|
669
|
-
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
|
|
670
799
|
});
|
|
671
800
|
joins.push({
|
|
672
|
-
condition
|
|
801
|
+
condition,
|
|
802
|
+
queryPath: targetQueryPath,
|
|
673
803
|
table: newAliasTable
|
|
674
804
|
});
|
|
675
|
-
} 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
|
+
});
|
|
676
815
|
joins.push({
|
|
677
|
-
condition
|
|
816
|
+
condition,
|
|
817
|
+
queryPath: targetQueryPath,
|
|
678
818
|
table: newAliasTable
|
|
679
819
|
});
|
|
680
820
|
}
|
|
@@ -690,6 +830,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
690
830
|
// A relationship jumps to a different collection, so localization does not carry over
|
|
691
831
|
parentIsLocalized: false,
|
|
692
832
|
pathSegments: pathSegments.slice(1),
|
|
833
|
+
req,
|
|
693
834
|
selectFields,
|
|
694
835
|
tableName: newTableName,
|
|
695
836
|
value
|
|
@@ -746,6 +887,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
746
887
|
locale,
|
|
747
888
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
748
889
|
pathSegments: pathSegments.slice(1),
|
|
890
|
+
req,
|
|
749
891
|
rootTableName,
|
|
750
892
|
selectFields,
|
|
751
893
|
selectLocale,
|
|
@@ -766,6 +908,7 @@ import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRela
|
|
|
766
908
|
locale,
|
|
767
909
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
768
910
|
pathSegments: pathSegments.slice(1),
|
|
911
|
+
req,
|
|
769
912
|
rootTableName,
|
|
770
913
|
selectFields,
|
|
771
914
|
selectLocale,
|