So I have this object, let's call it Dog, and this other object, let's call it Collar.
class Dog < ActiveRecord::Base
has_one :collar
end
class Collar < ActiveRecord::Base
belongs_to :dog
end
Can I get a list of dogs that have collars? Ideally in a slightly less awkward way than the following:
Dog.joins(:collar).where(Collar.arel_table['id'].not_eq(nil))
As a note to those who might wonder about the "arel_table" bit, it is the DB-agnostic way of saying "IS NOT NULL".