fix: correct prefix name when loading many_to_many relationships#736
Merged
zachdaniel merged 1 commit intoash-project:mainfrom Apr 14, 2026
Conversation
Commit 4ddcffe introduced a bug when loading many_to_many relationships living in a different schema. This commit fixes it.
zachdaniel
approved these changes
Apr 14, 2026
Contributor
|
🚀 Thank you for your contribution! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit 4ddcffe
introduced a bug when loading many_to_many
relationships living in a different schema.
This commit fixes it.
Contributor checklist
Leave anything that you believe does not apply unchecked.
Context
Loading
many_to_manyrelationships across different schemas is broken since commit.See issue "Wrong schema is being used when querying cross-schema many_to_many relationships" #735 for more details on how to reproduce it.
Integration tests in one of my projects indicated me the error. I then searched for the responsible commit, and IA helped me to find the right fix.
Concept
Detail
(from Claude Opus 4.5)
The code in
lateral_join_queryusedthrough_relationship.sourcefor schema prefix determination, which returned the wrong resource when the join table lived in a different PostgreSQL schema than the source resource. This caused queries to look for the join table in the wrong schema (e.g.,public.profile_interestsinstead ofprofiles.profile_interests).through_relationship.sourcerefers to the source resource of the relationship in the traversal path. For a many-to-many from Profile → Interest through ProfileInterest, thethrough_relationshipis the internal relationship used to traverse the path, and its.sourcepoints back to Profile (the original source), not the join table.through_resource.resourceis the resource module from theAsh.Querystruct that was explicitly constructed from the join table resource earlier in the code (inrelationships.ex). It directly contains the correct resource module (ProfileInterest).So when Profile is in "profiles" schema and ProfileInterest is also in "profiles" schema:
through_relationship.source→ Profile → correct by coincidencethrough_resource.resource→ ProfileInterest → correct by designBut when Interest is in "interest" schema and you load
interest.profiles:through_relationship.source→ Interest (wrong - "interest" schema)through_resource.resource→ ProfileInterest (correct - "profiles" schema)The fix works because
through_resourcewas already built from the right resource, so we just use that directly instead of trying to infer it from the relationship's source.Tests
I locally runned the tests. 2 are failing, but were already failing before this PR:
data_layer.ex(that will ensure this kind of bug should not happen in the future)