I have a model setup, for example:
class User has_many :items has_many :words, :through => :items end class Item belongs_to :user belongs_to :word default_scope where(:active => true) end class Words has_many :items end
The problem I encountered is that default_scope does not apply to the following association:
user.words
SQL instead:
SELECT `words`.* FROM `words` INNER JOIN `items` ON `words`.id = `items`.word_id WHERE ((`items`.user_id = 1)) AND ((`items.active = 1))
I get this SQL in the logs:
SELECT `words`.* FROM `words` INNER JOIN `items` ON `words`.id = `items`.word_id WHERE ((`items`.user_id = 1))
I believe this is because the default scope works for the regular model and its child association, but not for join tables.
What is the right way for Rails to get the join table area for collaboration between associations without having to specify it? Does it exist?
scope ruby-on-rails default-scope has-and-belongs-to-many has-many-through
joeellis
source share