title: Zero or one association in ActiveRecord
body: <p>I am writing a Ruby on Rails application that has two models - User and Farm. A User is considered a farmer if their farmer field is set to true. However, there is no seperate class for farmers. </p>
  
  <p>A User may have either one farm, or none at all. (I believe this is called a zero or one relationship). If I put:</p>
  
  <pre><code>has_one :farm
  </code></pre>
  
  <p>in the User model and</p>
  
  <pre><code>belongs_to :user
  </code></pre>
  
  <p>in the Farm model, this would create a one-to-one relationship between Users and Farms and mean that every User has a Farm. If I did the above, every User would have a Farm, and that would not make much sense since there are certain Users who cannot have a Farm. </p>
  
  <p>In short, what I want is for a User to have a Farm only if their farmer boolean is set to true. Otherwise, the relationship shouldn't exist. Is their a way to do this using ActiveRecord the way it is meant to be used?</p>