title: has_many belongs_to association with a foreign key
body: <p>Let's say you have two models <code>Venue</code> and <code>Photo</code>. Each <code>Venue</code> can have many <code>Photos</code>, but it can only have <em>one</em> <code>FeaturedPhoto</code>. Each <code>Photo</code> can be belong to many <code>Venues</code> and can be the <code>FeaturedPhoto</code> of more than one Venue too.</p>
  
  <p>I already have the general has_and_belongs_to_many relationship set up and working through a join table with these models:</p>
  
  <pre><code>class Photo &lt; ActiveRecord::Base
    mount_uploader :image, PhotoUploader
    has_and_belongs_to_many :venues
  end
  
  class Venue &lt; ActiveRecord::Base
    has_and_belongs_to_many :photos
  end
  </code></pre>
  
  <p>To add the FeaturedPhoto, it seems like I would need to add a column called featured_photo_id to the Venue model and then set up a has_many, belongs_to association between the two. But I'm not sure where to add the foreign_key info. Is this right?</p>
  
  <pre><code>class Photo &lt; ActiveRecord::Base
    mount_uploader :image, PhotoUploader
    has_and_belongs_to_many :venues
    has_many :venues
  end
  
  class Venue &lt; ActiveRecord::Base
    has_and_belongs_to_many :photos
    belongs_to :photo, foreign_key: "featured_photo_id", class_name: "Photo"
  end
  </code></pre>
  
  <p>Or do I have to add foreign_key info to both models?</p>