Alain Ravet
2006-Nov-05 17:11 UTC
self_referential has_many :through problem (can''t make it work)
Hi, I can''t make self referential has_many :through associations work: base_production.suggestions << suggested_production , where suggestions are stored in SQL: table: suggestionships column (production_id, suggestion_id) Rails: class Suggestionship < ActiveRecord::Base belongs_to :production belongs_to :suggestion , :class_name => ''Production'' end PROBLEM: ''suggestion_id'' is NULL, whenever a new ''suggestionship'' is created with foo.suggestions << bar THE MODEL : class Production < ActiveRecord::Base has_many :suggestionships has_many :suggestions , :through => :suggestionships , :source => :production end It must be obvious but I can''t see it. Any idea? TIA Alain --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jon Garvin
2006-Nov-06 16:45 UTC
Re: self_referential has_many :through problem (can''t make it work)
I believe this syntax... foo.suggestions << bar is only supported in Edge for has_many :through. So, for now, you''ll need to do something like... Suggestionship.create(:production_id => foo.id, :suggestion_id => bar.id) Alain Ravet wrote:> Hi, > > I can''t make self referential has_many :through associations work: > > base_production.suggestions << suggested_production > > , where suggestions are stored in > SQL: > table: suggestionships > column (production_id, suggestion_id) > Rails: > class Suggestionship < ActiveRecord::Base > belongs_to :production > belongs_to :suggestion , :class_name => ''Production'' > end > > > PROBLEM: > ''suggestion_id'' > is NULL, whenever a new ''suggestionship'' is created with > foo.suggestions << bar > > > THE MODEL : > > class Production < ActiveRecord::Base > has_many :suggestionships > has_many :suggestions , :through => :suggestionships , > :source => :production > end > > It must be obvious but I can''t see it. Any idea? > TIA > > Alain > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---