DB query from a belongs_to relationship
I have a model: Animal
belongs_to :owner
I have a model: Owner
has_many :animals
Owner has a boolean attribute active
def self.not_active
where('owner.active == ?', false)
end
The above code does not work for some reason. I've tried lots of things
around it, but keep getting errors. When calling something like
Animal.first.owner.active I get back either true or false, but the
database call must be different...
For clarification I want the Animals for which their owner is not active.
I don't want to do the opposite call though (Starting with the owner db
and checking active and returning animals) because of calls I'm linking
together off of Animal
No comments:
Post a Comment