I've got a model setup like the following:
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'm having is that the default_scope is not being applied to the following association:
user.words
Instead of this SQL:
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 figure this is because the default scope works for a regular model and its child association, but not for join tables.
What is the correct Rails way to get a join table scope to work between associations without needing to specify it? Does one exist?