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

Add configuration for auto_include(false) by default #55

Open
westonganger opened this issue May 19, 2017 · 8 comments

Comments

Projects
None yet
3 participants
@westonganger
Copy link

commented May 19, 2017

Is there the ability to set goldiloader to set the whole application to auto_include(false) by default? I only want to use goldiloader for certain controller actions. I think I need something like:

Goldiloader.config do |config|
 config.auto_include = false
end

Then when I want to use it I can do the following

@posts = Post.auto_include # preferable
# or
@posts = Post.auto_include(true)
@jturkel

This comment has been minimized.

Copy link
Member

commented May 19, 2017

We don't currently have this configuration option. Can you elaborate on why you only want to use goldiloader for certain controller actions (or is it certain models)? Also note the auto_include query scope method does not apply recursively e.g. Blog.auto_include will enable automatic eager loading of the blog's posts associations but it will not enable automatic eager loading of the post's associations.

@westonganger

This comment has been minimized.

Copy link
Author

commented May 19, 2017

Yeah it was for nested includes. That kills the main purpose for this. However it may be nice to implement this so its not an all or nothing approach.

@westonganger westonganger changed the title Add configuration for Add configuration for auto_include(false) by default May 19, 2017

@jturkel

This comment has been minimized.

Copy link
Member

commented May 19, 2017

One possibility would be to implement a block form of auto_include that would apply for the scope of the block e.g.

Blog.auto_include do
  Blog.all.find_each do |blog|
    posts = blog.posts
    ...
  end
end
@westonganger

This comment has been minimized.

Copy link
Author

commented May 19, 2017

Thats another interesting idea which could make this library pretty powerful. I think both of these ideas should be added.

@jturkel

This comment has been minimized.

Copy link
Member

commented May 19, 2017

I'm totally open to implementing this enhancement but can you elaborate on why you don't want to enable goldiloader by default? What are the scenarios where it's not working for you?

@westonganger

This comment has been minimized.

Copy link
Author

commented May 19, 2017

Well it was to do with the nested includes, that argument is now void. Its just a lot of magic, I could see some people might like it be more explicit and opt-in only when they want, they should have that option.

@sobrinho

This comment has been minimized.

Copy link
Contributor

commented Oct 8, 2018

@jturkel I can make a PR for this one.

Just wondering if that makes sense to implement! :)

@jturkel

This comment has been minimized.

Copy link
Member

commented Oct 8, 2018

I'd be open to a change that adds a global configuration for enabling/disabling golidloader (as long as the default is enabled) + a block form of auto_include(enabled = true) as long as it interacts cleaning with the auto_include query scope introduced in #52.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.