title: Optional or Conditional model associations in Rails
body: <p>I have a user model.
  Users can have 1 of 3 roles: role1, role2, role3. This is represented by a 'role' column in the user model.
  Each role has a unique profile. role1_profile, role2_profile, role3_profile. Each *_profile is a model.</p>
  
  <p>How do I represent this optional association in Rails?</p>
  
  <p>I've tried it two different ways: </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      #FIRST WAY
      if current_user.role == 'role1' then has_one :role1_profile end 
      #SECOND WAY
      has_one :role1_profile, :conditions =&gt; ['user.role = ?', 'role1']
  end
  </code></pre>
  
  <p>But that doesn't work. What is the right way to do this? </p>