Nested :through associations

Hi all,

In October I worked on a patch for a long-requested feature: associations that can go :through anything, including other :through associations.

The Lighthouse ticket is here: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1152

I believe this is a robust, well-tested patch. I want to get it merged, but there has been very little response to the patch on Lighthouse. I should probably have posted on here before now - but here I am now anyway.

Can anyone help verify/review this patch? Any suggestions about how best to get it accepted by the core team?

Also, can somebody with the relevant permissions changes the status from "incomplete" to "open" please? I am actively maintaining the branch and merging in the latest master from time to time. I will also happily deal with any issues which arise as a result of this patch.

Thanks, Jon Leighton

Jon, I would make sure this currently merges into master and send a pull request on github with the lighthouse ticket in the comments... Need get more eyes on it.

The patch has now been "verified" on Lighthouse. I.e. 3 people have tested and +1ed it. I've done a pull request here: https://github.com/rails/rails/pull/121

I merged latest master over the weekend and will continue to merge as necessary to keep it up to date.

Jon

Hi all,

Jose has responded on the pull request:

I’m very much in favor of hmt working to an infinite depth. From my own experience as well as responding to others, I know it’s something that people just expect to work.

I’m also concerned about bugs, but I like your suggestion Jon.

+1 for sorting bugs out and commiting this. HMT just helps doing some associations where it would be hard to do. Even if it is not fool proof, allowing us to associate models further where needed is welcomed. I have been in a couple of projects where coding would be easier with this patch.

+1 for the usefulness of Jon's patch. During a previous project I was very disappointed to find that Rails didn't support nested :through associations. Besides my own experiences, a quick search on Google for "nested has many through associations" shows a litany of blog posts and discussions on hacks to simulate the functionality.

For example: http://justinfrench.com/notebook/nested-hasmany-through-associations-in-rails http://geoff.evason.name/2010/04/23/nested-has_many-through-in-rails-or-how-to-do-a-3-table-join/

I agree too with José Valim's comments that has_many :through needs to be fixed. The surprising inconsistencies between has_many :through and has_many adds cognitive load to developers and, for me at least, the lack of dependent options has pushed me into using has_many over has_many :through quite a bit. If Jon's code and proposed audit can help iron out these issues then all the better!