-
-
Notifications
You must be signed in to change notification settings - Fork 668
Description
Description
When using Select::find_also_linked, SelectTwo::and_also_related does not left join on the aliased name of the linked table. The constructed query at the point of creating SelectTwo does not consider that the previous relationship may have aliased the joined table.
Steps to Reproduce
I think this can be summed up by this, where PostAuthor is Linked<FromEntity = posts::Entity, ToEntity = users::Entity>:
let (post, author, address) = posts::Entity::find_by_id(id)
.find_also_linked(PostAuthor)
.and_also_related(address::Entity);Expected Behavior
I expected to get the related address of the author
Actual Behavior
I believe (but have not verified) that this fails for all database types. For postgres, this error is: invalid reference to FROM-clause entry for table "users"", detail: None, hint: Some("Perhaps you meant to reference the table alias "r0".")
Reproduces How Often
Always except if the table name is r<N> where N is a zero-indexed count of linked aliases, and the table's name lines up exactly with the position of its alias.
Workarounds
- Creating a
FromQueryResulttype (in1.x). Unsure for2.x - Loading the related table with
LoaderTraitinv1
Versions
v1. I snooped around to discover that the same issue exists in v2 in src/query/join.rs:253.