Skip to content

Commit 998a4a6

Browse files
committed
fix(directus): update primary key selection
1 parent 207b1c7 commit 998a4a6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@replexica/integration-directus": patch
3+
---
4+
5+
Update primary key selection

integrations/directus/src/api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ export default defineOperationApi<Options>({
6161
const languagesService = new ItemsService(language_table, { schema });
6262
const translationsService = new ItemsService(translation_table, { schema });
6363

64+
// Get the primary key field for the collection
65+
const collection_pk = schema.collections[collection].primary;
66+
6467
// Get collection fields and their types
6568
const collectionFields = schema.collections[translation_table].fields;
6669

6770
// Get all existing translations for this item
6871
const existingTranslations = await translationsService.readByQuery({
6972
fields: ['*'],
7073
filter: {
71-
[`${collection}_id`]: { _eq: item_id }
74+
[`${collection}_${collection_pk}`]: { _eq: item_id }
7275
}
7376
});
7477

@@ -189,7 +192,7 @@ export default defineOperationApi<Options>({
189192
result = await translationsService.createOne({
190193
...translatedData,
191194
languages_code: language.code,
192-
[`${collection}_id`]: item_id
195+
[`${collection}_${collection_pk}`]: item_id
193196
});
194197
}
195198

0 commit comments

Comments
 (0)