Sorry for the long post…
I’m having difficulties with accessing my data using has_many through
associations. For simplicity, I’ll reference the Agile Web D.
example on this topic.
has_many :users, :through => :readings
belongs_to :article, :foreign_key => :article_id
belongs_to :user, :foreign_key => :user_id
has_many :articles, through => readings
I’m dealing with legacy data and so the glitch to this set up is that
the articles table is has id as the primary key and article_id is
another field in the table. I want the readings table to connect to the
articles table via article.article_id, not article.id.
The end result that I want to see is providing a user (user.id = 1) and
then output a report that shows me a list of all of the articles that
user 1 has read and tell me each time user 1 read the article.
Article id = 1
Reading id = 1 3/23/2008
Reading id = 2 3/14/2008
Reading id = 3 3/7/2008
Article id = 2
Reading id = 4 3/15/2008
Reading id = 5 3/3/2008
Right now, the query that I get back is
left outer join readings
readings.article_id = articles.id
where user_id = 1
Any ideas on how to change my relationships so that I can connect
readings to articles?