Monday, April 11, 2011

How deep (how many tables away) can my [has_many :through] association "path" be?

The following db design example is given in the Agile Rails book to teach the has_many :through code...

[Article]----<[Readings]>----[User]

This is all quite easy to understand at first. However, I have a situation where the following db design might be used:

[Genre]-----<[Article]-----<[Readings]>-----[User]

Now here is my question:

Can I use the has_many :through association so that I can code something like the following:

artistic_minded _users = art.users

If this can be done then how do you setup the has_many association??

From stackoverflow
  • This isn't possible out of the box in Rails. Try to look for the nested_has_many_through plugin or something similar (as I'm not sure if its code has been updated for the latest versions of Rails).

0 comments:

Post a Comment