I’m trying to figure out the best way to display some summary
my app (an article submission database for writers), and I’m not quite
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 :articles, :through => :submissions
class Article < ActiveRecord::Base
has_many :markets, :through => :submissions
class Submission < ActiveRecord::Base
class Action < ActiveRecord::Base
belongs_to :article , :through => :submissions
belongs_to :market , :through => :submissions
The two things I’d like to accomplish are:
- A list of the most recent Action for each Submission associated with a
- A list of the most recent Action for each Article associated with a
All of my tables have created_at and updated_at fields, so the concept
“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
data I need.
Can anyone help? Thanks in advance!