# Most recent detail record for master records - what's the be

**URL:** <https://www.ruby-forum.com/t/most-recent-detail-record-for-master-records-whats-the-be/96406>\
**Category:** Rails\
**Created:** [June 28, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/most-recent-detail-record-for-master-records-whats-the-be/96406 "2006-06-28T17:28:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tammy\_Cravit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tammy\_Cravit](https://www.ruby-forum.com/u/Tammy_Cravit)\
**Post date:** [June 28, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/most-recent-detail-record-for-master-records-whats-the-be/96406/1 "2006-06-28T17:28:57Z")

</div>

I’m trying to figure out the best way to display some summary  
information in  
my app (an article submission database for writers), and I’m not quite  
sure  
how to get ActiveRecord to give me what I want.

Here’s what the relevant part of my data model looks like:

* * *

class Market \< ActiveRecord::Base  
has\_many :submissions  
has\_many :articles, :through =\> :submissions  
end

class Article \< ActiveRecord::Base  
has\_many :submissions  
has\_many :markets, :through =\> :submissions  
end

class Submission \< ActiveRecord::Base  
belongs\_to :market  
belongs\_to :article  
has\_many :actions  
end

## class Action \< ActiveRecord::Base belongs\_to :submission belongs\_to :article , :through =\> :submissions belongs\_to :market , :through =\> :submissions end

The two things I’d like to accomplish are:

- A list of the most recent Action for each Submission associated with a  
given Article
- A list of the most recent Action for each Article associated with a  
given  
Market

All of my tables have created\_at and updated\_at fields, so the concept  
of  
“most recent” is there in my database. But I’m not sure 100% sure my  
associations are correct, nor am I sure what the best way is to get back  
the  
data I need.

Can anyone help? Thanks in advance!

– Tammy
