Repository navigation
fix: fromSub alias on a model, find and pluck on a union - #39
Conversation
- fromSub() on a model now keeps the alias in tableAlias. The soft delete check and the chunk() order use it, not the model table. - find(), findOrFail(), pluck(), pluckMap() and valueOf() throw a StateError on a union() query. Before, they gave a wrong row or an SQL error.
Their where went to the first part of a union only, so they could find or write the wrong row. They now throw a StateError, like find(). The check is one shared checkNoUnion() in union.dart.
Bot reviewVerdict: changes requested (1 blocking item). Checked: Blocking
Nits (not blocking)
|
update(), delete() and restore() run on the model table. After the fromSub() alias fix, their soft delete check used the alias, so they failed with no such column: b.deleted_at. Writes now use the table name. Reads keep the alias.
Fixer replyFixed the blocker in the new commit.
|
Bot reviewVerdict: OK, nothing blocks. Checked:
Nits:
|
Three bugs for the 3.1.0 release.
1.
fromSub()on a model ignores the aliasProblem:
Blog().fromSub(sub, 'b').get()failed withno such column: blog.deleted_at.chunk()failed the same way.Cause:
fromSub()setstableName = alias. A model readstableNamefrom its class, so the set does nothing on a model.Fix:
fromSub()also setstableAlias. The soft delete check already usestableAlias ?? tableName._qualified()(used bychunk()and the cursor) now does too.2.
find()on a union gives the wrong rowProblem:
t().where('status','zzz').union(t().where('status','y')).find(1)gave uid 2.Cause: the id check goes to the first part only.
LIMIT 1goes to the whole union.Fix:
find()(so alsofindOrFail()) throws aStateErroron a union, likeall().getFirst()andfirstOrFail()are not changed. They add onlyLIMIT 1to the whole union, so they give the right row. A test checks this.3.
pluck(),pluckMap(),valueOf()on a union give an SQL errorCause: only the first part gets the select.
Fix: the same clear
StateError.Tests
test/bug_fixes_test.dart.dart analyze: no issues.