title: Rails - has_one relationship : scopes for associated and non-associated objects
body: <p>I have this relationship : a user can have zero or one dog, but a dog has to belong to someone.</p>
  
  <pre><code># dog.rb
  class Dog &lt; ActiveRecord::Base
    belongs_to :user
  end
  
  # user.rb
  class User &lt; ActiveRecord::Base
    has_one :dog
  end
  </code></pre>
  
  <p>I want to define the following scopes :</p>
  
  <pre><code>User.with_a_dog
  User.without_a_dog
  </code></pre>
  
  <p>I can do this for the first case, because the joins are INNER JOIN by default in rails :</p>
  
  <pre><code>scope :with_a_dog, :joins(:dog)
  </code></pre>
  
  <p>1/ Is this solution for the first scope good enough?</p>
  
  <p>2/ What would you do for the second one?</p>
  
  <p>3/ (Somewhat related) Is there a better way of doing this? :</p>
  
  <pre><code># user.rb
  def has_a_dog?
    !self.dog.nil?
  end
  </code></pre>
  
  <p>Thanks for your help!</p>