Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5839 Fix eager-loading from STI subclasses #5934

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

jamis
Copy link
Contributor

@jamis jamis commented Jan 15, 2025

If the root of a query is an STI subclass (e.g. Subclass.all) AND the query tries to eager load (includes) another association, the eager load was failing because it was looking for inverse associations using the STI subclass name, instead of the class at the root of the hierarchy.

If the root of a query is an STI subclass (e.g. `Subclass.all`)
AND the query tries to eager load (`includes`) another association,
the eager load was failing because it was looking for inverse
associations using the STI subclass name, instead of the class at
the root of the hierarchy.
@GCorbel
Copy link

GCorbel commented Jan 15, 2025

I just tried and the fix work with Mongoid 8.0.8. Thanks.

I had to change because the model I used didn't include Traversable so I replaced queue.push(klass.root_class.to_s) if klass != klass.root_class by

      root_class = self.klass
      root_class = root_class.superclass while root_class.hereditary?

      queue.push(root_class.to_s) if klass != root_class

@stanley90
Copy link
Contributor

Any update on this?

@jamis
Copy link
Contributor Author

jamis commented Jan 21, 2025

@stanley90 sorry, some illness and a long weekend left this one in a bit of limbo. I hope to push it across the finish line (and backport it as necessary) in the next couple of days.

@jamis jamis removed the request for review from DarshanaVenkatesh January 21, 2025 16:13
@jamis jamis merged commit 837f255 into mongodb:master Jan 22, 2025
67 checks passed
@jamis jamis deleted the 5839-eager-loading-sti branch January 22, 2025 14:56
jamis added a commit to jamis/mongoid that referenced this pull request Jan 22, 2025
If the root of a query is an STI subclass (e.g. `Subclass.all`)
AND the query tries to eager load (`includes`) another association,
the eager load was failing because it was looking for inverse
associations using the STI subclass name, instead of the class at
the root of the hierarchy.
jamis added a commit to jamis/mongoid that referenced this pull request Jan 22, 2025
If the root of a query is an STI subclass (e.g. `Subclass.all`)
AND the query tries to eager load (`includes`) another association,
the eager load was failing because it was looking for inverse
associations using the STI subclass name, instead of the class at
the root of the hierarchy.
jamis added a commit that referenced this pull request Jan 22, 2025
If the root of a query is an STI subclass (e.g. `Subclass.all`)
AND the query tries to eager load (`includes`) another association,
the eager load was failing because it was looking for inverse
associations using the STI subclass name, instead of the class at
the root of the hierarchy.
jamis added a commit that referenced this pull request Jan 22, 2025
If the root of a query is an STI subclass (e.g. `Subclass.all`)
AND the query tries to eager load (`includes`) another association,
the eager load was failing because it was looking for inverse
associations using the STI subclass name, instead of the class at
the root of the hierarchy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants