-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Eager load has_one and has_many in the list view so they can be searched. #2441
Conversation
Always forcing eager load of |
@@ -120,7 +120,7 @@ def check_for_cancel | |||
end | |||
|
|||
def get_collection(model_config, scope, pagination) | |||
associations = model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name } | |||
associations = model_config.list.fields.select { |f| f.type.in?([:belongs_to_association, :has_one_association, :has_many_association]) && !f.polymorphic? }.collect { |f| f.association.name } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there another way we could do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_collection(model_config, scope, pagination)
associations = _associations_for_collection(model_config)
# etc
end
def _associations_for_collection(model_config)
model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name }
end
so that we can customize it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. bf4@53e53f4
e.g. it allows someone to [eager load has_one and has_many associations](railsadminteam#2441) without requiring a change in RailsAdmin: ```diff def get_associations_for_collection(model_config) - model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name } + model_config.list.fields.select { |f| f.type.in?([:belongs_to_association, :has_one_association, :has_many_association]) && !f.polymorphic? }.collect { |f| f.association.name } end ```
e.g. it allows someone to [eager load has_one and has_many associations](railsadminteam#2441) without requiring a change in RailsAdmin: ```diff def get_associations_for_collection(model_config) - model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name } + model_config.list.fields.select { |f| f.type.in?([:belongs_to_association, :has_one_association, :has_many_association]) && !f.polymorphic? }.collect { |f| f.association.name } end ```
e.g. it allows someone to [eager load has_one and has_many associations](railsadminteam#2441) without requiring a change in RailsAdmin: ```diff def get_associations_for_collection(model_config) - model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name } + model_config.list.fields.select { |f| f.type.in?([:belongs_to_association, :has_one_association, :has_many_association]) && !f.polymorphic? }.collect { |f| f.association.name } end ```
e.g. it allows someone to [eager load has_one and has_many associations](railsadminteam#2441) without requiring a change in RailsAdmin: ```diff def get_associations_for_collection(model_config) - model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association.name } + model_config.list.fields.select { |f| f.type.in?([:belongs_to_association, :has_one_association, :has_many_association]) && !f.polymorphic? }.collect { |f| f.association.name } end ```
Eager load has_one and has_many in the list view so they can be searched.