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

Auto eager loading broken for has_many through associations where the model is an STI subtype #12

Closed
jturkel opened this issue Jun 27, 2014 · 3 comments

Comments

@jturkel
Copy link
Member

jturkel commented Jun 27, 2014

Example models:

class Group < ActiveRecord::Base
  has_many :users
  has_many :articles, through: :users
end

class User < ActiveRecord::Base
  belongs_to :group
  has_many :articles
end

class Post < ActiveRecord::Base
  belongs_to :user
end

class Article < Post
end

Can't auto eager load (or regular eager load) Group#articles.

Underlying issue is rails/rails#11078. Workaround is to set auto_include = false on these associations

@jturkel
Copy link
Member Author

jturkel commented Mar 5, 2016

I've confirmed this is still an issue on Rails master.

mayra-cabrera pushed a commit to gitlabhq/gitlabhq that referenced this issue Apr 9, 2018
Goldiloader is great, but has several issues with has_many :through relations:

* salsify/goldiloader#12
* salsify/goldiloader#14
* salsify/goldiloader#18

Rather than try to figure out which applies in each case, we should just do the
drudge work of manually disabling autoloading for all relations of this type. We
can always use regular preloading for specific cases, but this way we avoid
generating invalid queries through Goldiloader's magic.
@sfcgeorge
Copy link

I just tried Goldiloader and immediately had some issue involving the STI type field. However it seems to be fixed in Rails 5.2 (finally) and sure enough upgrading does seem to have fixed my issue :) rails/rails#14312

So, if anyone else experiencing STI issues with Goldiloader could upgrade to Rails 5.2 and confirm that the issue is fixed for them too, then I think this issue could be closed.

@jturkel
Copy link
Member Author

jturkel commented Jul 10, 2018

Nice! I've confirmed this is fixed in 5.2.0 via the following gist.

@jturkel jturkel closed this as completed Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants