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

Eager load has_one and has_many in the list view so they can be searched. #2441

Closed
wants to merge 1 commit into from

Conversation

bf4
Copy link
Contributor

@bf4 bf4 commented Oct 21, 2015

Eager load has_one and has_many in the list view so they can be searched.

@bf4 bf4 changed the title Remove SafeYAML Eager load has_one and has_many in the list view so they can be searched. Oct 21, 2015
@mshibuya
Copy link
Member

mshibuya commented Nov 3, 2015

Always forcing eager load of :has_many association is not acceptable.
What if each of users has thousands of blog posts? Loading of user index page will be stuck.

@mshibuya mshibuya closed this Nov 3, 2015
@@ -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 }
Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bf4 pushed a commit to bf4/rails_admin that referenced this pull request Jun 6, 2016
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
```
bf4 pushed a commit to bf4/rails_admin that referenced this pull request Jun 6, 2016
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
```
bf4 pushed a commit to bf4/rails_admin that referenced this pull request Jun 6, 2016
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
```
bf4 pushed a commit to bf4/rails_admin that referenced this pull request Jun 6, 2016
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
```
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.

3 participants