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'm trying to get an association from Project has_many :invoices, :through => :tasks
When I tried that, I get:
Invalid source reflection macro :has_many :through for has_many :invoices, :through => :tasks. Use :source to specify the source reflection.
I'm a little at a loss to if this is possible, and if so, how to use :source correctly
Ryan is right, this is supported from Rails 3.1. Extracted from the release notes:
Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations.
Src: http://guides.rubyonrails.org/3_1_release_notes.html
You can't do this in Rails 3.0. In Rails 3.1 I think this will be possible.
Instead, you have to use the nested_has_many_through plugin: http://github.com/ianwhite/nested_has_many_through
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With