Self_referential has_many :through problem (can't make it wo

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

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)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs