: has_many: through associations two levels in depth

Project has_many :tasks Task has_many :invoices, :through => :line_items has_many :line_items LineItems belongs_to :invoice belongs_to :task Invoice has_many :tasks, :through=> :line_item has_many :line_items 

I am trying to get an association from Project has_many: invoices ,: through =>: tasks

When I tried this, I get:

Invalid source reflection macro: has_many: through for has_many: invoices ,: through =>: tasks. Use: source to indicate the reflection of the source.

I do not understand a bit if this is possible, and if so, how to use: source correctly

+7
source share
2 answers

Ryan is right, this is supported by Rails 3.1. Extracted from the release notes:

Now associations with the: through option can use any association as a through or source association, including other associations that have the: through and has_and_belongs_to_many associations.

Src: http://guides.rubyonrails.org/3_1_release_notes.html

+5
source

You cannot do this in Rails 3.0. In Rails 3.1, I think it will be possible.

Instead, you should use the nested_has_many_through plugin: http://github.com/ianwhite/nested_has_many_through

+3
source

All Articles