title: Rails - has_one association with two parameters
body: <p>I have a table called assets which has many versions. The versions have version numbers. Each asset also has a version_number column which indicated the most recent (newest) version.</p>
  
  <p>I would like to set up an association between an asset and its latest version, but I can't find any documentation on how to do that. It would, in theory, look something like this</p>
  
  <p>asset.rb</p>
  
  <pre><code>has_one :latest, class_name: "Version", foreign_key: ["asset_id", "version_number"], primary_key: ["id", "version_number"]
  </code></pre>
  
  <p>A naive approach would be:</p>
  
  <p>asset.rb</p>
  
  <pre><code>def latest
    Version.where(asset_id: asset.id, version_number: asset.version_number).first
  end
  </code></pre>
  
  <p>The problem with doing it just like that in code though, is that I can't load the 'latest' in the association_cache of an asset. I also can't easily eager-load all the assocationed 'latest' records when I load a set of assets, like <code>Asset.includes(:latest).where(project_id: 7)</code>.</p>
  
  <p>The reason I think that this <em>should</em> be possible is because polymorphic associations use two parameters.</p>