I have this attitude: the user may have zero or one dog, but the dog must belong to someone.
# dog.rb class Dog < ActiveRecord::Base belongs_to :user end # user.rb class User < ActiveRecord::Base has_one :dog end
I want to identify the following areas:
User.with_a_dog User.without_a_dog
I can do this for the first case, because the default connections are INNER JOIN in rails:
scope :with_a_dog, :joins(:dog)
1 / Is this solution for the first area good enough?
2 / What would you do for the second?
3 / (A bit related) Is there a better way to do this?
# user.rb def has_a_dog? !self.dog.nil? end
Thank you for your help!
source share