Querying related tables on a linked table fails
@Huliiiiii is already working on this.
Since Feb 19, 2026.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.