title: Rails: With models A has_many B belongs_to C return A where B belongs to C and B is most recently created for given A?
body: <p>I have three models A, B, and C, where <code>A has_many B</code>; <code>B belongs to C</code>, and <code>B has a created_on timestamp</code>. C has_many A through B.</p>
  
  <p>I want to return <i>all</i> A where A has a B that belongs to C and where B is the most recently created B for that A.  </p>
  
  <p>I can do this with a method loop.  Can this be done solely with named_scopes?, or is some other elegant/efficient manner?  </p>
  
  <p>As per request for real world (TM) examples A, B and C can be imagined as, for instance, Pets (A), PetsName (B), and Names (C). PetsNames are given to Pets at a specific time, and any given Name can be given to many Pets.  Any Pet can have many Names (a :through relationship).  For a given Name I want <i>all</i> of the Pets in which that Name is the most recently created PetName for that Pet.  The call may look something like <code>@name.pets.most_recently_named_as</code></p>