On 14 January 2012 16:59, Fritz Rodriguez <li...@ruby-forum.com> wrote: > Colin Law wrote in post #1040834: >> On 14 January 2012 04:12, Fritz Rodriguez <li...@ruby-forum.com> wrote: >>> >>> class NameAlias < ActiveRecord::Base >>> belongs_to :work_order >>> has_many :sub_tasks >>> end >>> >>> class SubTask < ActiveRecord::Base >>> belongs_to :name_alias >>> belongs_to :work_order >> >> This should be belongs_to :through name_alias. It must mirror the >> has_many sub_tasks :through in work_order >> >> You should really have started a new thread for this as it is nothing >> to do with the original post. >> >> Colin > > Colin, Thanks for your reply and my apologies regarding proper placement > of the is post. > > I believe you said the SubTask model should mirror through in > work_order? > > class SubTask < ActiveRecord::Base > attr_accessible :name_alias_id, :work_order_id, :status, :title > > belongs_to :name_alias > belongs_to :work_order, :through => :name_alias > > accepts_nested_attributes_for :name_alias > accepts_nested_attributes_for :work_order > > This produced a "Unknown key: through" error? Not sure I place the > association in the correct model, I have attached a file for reference. > I appreciate your help! > > Attachments: > http://www.ruby-forum.com/attachment/6910/has_many_through.txt
By the way, in the attachment you have multiple default scopes for WorkOrder. I think only one is allowed. You can order by multiple fields in one scope of course if that is what you want. Be careful with specifying the order in default scope though, it is not possible to override this (or at least it did not used to be possible) as the default scope order is applied *after* any others. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.