Add support for nested eager loading on namespaced relation classes#1
Open
lucasmartins wants to merge 1 commit intomasterfrom
Open
Add support for nested eager loading on namespaced relation classes#1lucasmartins wants to merge 1 commit intomasterfrom
lucasmartins wants to merge 1 commit intomasterfrom
Conversation
I was getting the following error when doing [nested eager loading](https://jira.mongodb.org/browse/MONGOID-4173), when relations are not the default `belongs_to :other_thing`: ``` NameError: uninitialized constant OtherClass from /Users/lucasmartins/.gem/ruby/2.3.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `const_get' ``` This is a relation like I'm using: ```ruby class NS::ModuleName::MyClass belongs_to :other_class, class_name: NS::ModuleName::OtherClass.to_s, index: true, touch: true end class NS::ModuleName::OtherClass has_many :my_class, class_name: NS::ModuleName::MyClass.to_s, index: true, touch: true end ``` While debugging the code, I've noticed the `get_inclusion_metadata` method was trying to `constantize` `"other_class"` instead of `"NS::ModuleName::OtherClass"`. ``` def get_inclusion_metadata(_klass, association) if _klass.is_a?(Class) _klass.reflect_on_association(association) else # here, _klass.to_s.classify was "OtherClass", while it should be "NS::ModuleName::OtherClass" _klass.to_s.classify.constantize.reflect_on_association(association) end end ``` I'm not sure about performance impact though. I need somebody who knows this codebase better to check it out. Any thoughts?
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.
I was getting the following error when doing nested eager loading, when relations are not the default
belongs_to :other_thing:This is a relation like I'm using:
While debugging the code, I've noticed that
get_inclusion_metadatawas trying toconstantize"OtherClass"instead of"NS::ModuleName::OtherClass".I'm not sure about performance impact though.
I need somebody who knows this codebase better to check it out.
Any thoughts?