Last active
December 23, 2015 00:09
-
-
Save vzaremba/6551391 to your computer and use it in GitHub Desktop.
Rails - filter using join model on has_many through.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
has_many :accounts | |
has_many :computers, through: :accounts | |
end | |
class Account | |
belongs_to :person | |
belongs_to :computer | |
scope :administrators, -> { where(role: 'administrator') } | |
end | |
class Computer | |
has_many :accounts | |
has_many :people, through: :accounts | |
end | |
person.computers.merge(Account.administrators) # very nice! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment