I have a database schema with a few levels of nesting. Let's say it has a User
model which has_many
Foo
, and Foo
has_many
Bar
, and Bar
has_many
Baz
. Now let's say I want to return all of the Baz
belonging to a given User
. Of course, there is a way to get that with just the associations above, but to my knowledge, it's circuitous.
For convenience, I've just been saying that User
has_many
Foo
, Bar
, and Baz
. Then I can bring up any records belonging to a User
easily. Furthermore, anytime I find myself regularly needing to access an association that's a few levels of nesting away, I just go ahead and create a direct association. It seems to have been working fine so far.
I can't really find much about this practice on the web, so my fear is that it's not done much and maybe isn't a good one. Is this OK? Is there a better way to move nested through nested associations like this?