-
-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
Description
Rails is not smart when the subject is association shortcuts.
Something like:
class Text < ActiveRecord::Base
belongs_to :user
has_many :user_comments, through: :user, source: :comments
end
class User < ActiveRecord::Base
has_many :comments
end
query = Text.includes(user: :comments).strict_loading
query.first.user_comments # Raises errorWe can safely assume that: Because association :user_comments has no scope, it is the equivalent of calling user.comments, as long as the comments association was loaded without any additional scope (or even equivalent scopes).
The idea is to assign the @target and mark the association as loaded as long as it complies with the necessary requirements. Otherwise, just go ahead and load the association.