brick
brick copied to clipboard
Query association with WherePhrase doesn't work with Supabase
Issue with WherePhrase and association columns in Brick
Based on the test:
https://github.com/GetDutchie/brick/blob/063b85324b1c7d28aa12bd9af1319917e677a912/packages/brick_sqlite/test/query_sql_transformer_test.dart#L366-L387
When I apply similar logic in my code, I get an error from Supabase:
Query(
where: [
Where.exact("group", Or("creatorId").isExactly(localId)),
Where.exact("person", WherePhrase([
const Or("id").isExactly(profileId),
const Or("cloudId").isExactly(cloudId)
]), isRequired: false)
],
)
The error I receive:
I/flutter (5044): OfflineFirstRepository: WARNING: #hydrate supabase failure: PostgrestException(message: column _group_members_.cloud_id does not exist, code: 42703, details: Bad Request, hint: Perhaps you meant to reference the column "_group_members_.group_id".)
Observation: Brick seems to interpret the columns inside the WherePhrase as belonging to the parent table, not the associated table. This causes invalid SQL when querying associations.
Work around
Query without WherePhrase in association query
Query(
where: [
Where.exact("group", Or("creatorId").isExactly(localId)),
Where.exact("person", Or("id").isExactly(profileId)),
Where.exact("person", Or("cloudId").isExactly(cloudId)),
],
)