Issue with WherePhrase and association columns in Brick
Based on the test:
|
test('OR', () async { |
|
const statement = |
|
'SELECT DISTINCT `DemoModel`.* FROM `DemoModel` INNER JOIN `DemoModelAssoc` ON `DemoModel`.assoc_DemoModelAssoc_brick_id = `DemoModelAssoc`._brick_id WHERE (`DemoModelAssoc`.id = ? OR `DemoModelAssoc`.full_name = ?)'; |
|
final sqliteQuery = QuerySqlTransformer<DemoModel>( |
|
modelDictionary: dictionary, |
|
query: Query( |
|
where: [ |
|
Where.exact( |
|
'assoc', |
|
WherePhrase([ |
|
const Or('id').isExactly(1), |
|
const Or('name').isExactly('Guy'), |
|
]), |
|
), |
|
], |
|
), |
|
); |
|
|
|
expect(sqliteQuery.statement, statement); |
|
await db.rawQuery(sqliteQuery.statement, sqliteQuery.values); |
|
sqliteStatementExpectation(statement, [1, 'Guy']); |
|
}); |
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)),
],
)
Issue with
WherePhraseand association columns in BrickBased on the test:
brick/packages/brick_sqlite/test/query_sql_transformer_test.dart
Lines 366 to 387 in 063b853
When I apply similar logic in my code, I get an error from Supabase:
The error I receive:
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
WherePhrasein association query