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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs