From b8a2f19098137f1fe66f2130846179ee66ce0487 Mon Sep 17 00:00:00 2001 From: Kobie Botha Date: Mon, 8 Dec 2025 10:51:37 -0700 Subject: [PATCH] better composite ID column example --- usage/sync-rules/client-id.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usage/sync-rules/client-id.mdx b/usage/sync-rules/client-id.mdx index 8c324d2e..9a0d8ef2 100644 --- a/usage/sync-rules/client-id.mdx +++ b/usage/sync-rules/client-id.mdx @@ -18,11 +18,13 @@ SELECT client_id as id FROM my_data MongoDB uses `_id` as the name of the ID field in collections. Therefore, PowerSync requires using `SELECT _id as id` in [Sync Rule's](/usage/sync-rules) data queries when using MongoDB as the backend source database. When inserting new documents from the client, prefer `ObjectId` values for `_id` (stored in the client's `id` column). -Custom transformations could also be used for the ID, for example: +Custom transformations can also be used for the ID column. This is useful in certain scenarios for example when dealing with join tables, because PowerSync doesn't currently support composite primary keys. For example: ```sql -- Concatenate multiple columns into a single id column -SELECT org_id || '.' || record_id as id FROM my_data +SELECT item_id || '.' || category_id as id, * FROM item_categories + +-- the source database schema for the above example is CREATE TABLE item_categories(item_id uuid, category_id uuid, PRIMARY KEY(item_id, category_id)); ```