small medium large xlarge

07 Mar 2009, 03:30
Philip R. Dutton (1 post)

The book discusses how to use the has_many :through association with the following db design example: ` [Articles]—-<[Readings]>—-[Users] `

As a Rails newbie I was eventually confused about why I could not use a similar has_many :through association with the following db design example: ` [Genres]—-<[Articles]—-<[Readings]>—-[Users] `

In the above db diagram I would have liked to use Rails to give me all users who have read articles belonging to a particular Genre: art_genre.users #returns collection.

Eventually I realized I had to resort to a finder_sql option with which I was required to write the full query (after which I then had to utilize the rails “group_by” command. All of this seemed like a bit of hackety-hack. I am still learning about how to best do this according to “the rails way.”

So my suggestion is that the authors could briefly compare and contrast the above db diagrams in context of the discussion of the has_many :through association. It was not immediately clear to me that I could only use the has_many :through association with tables that were directly “linked” to the join table in question.

Thanks for the consideration!

You must be logged in to comment