Hello, despite many readings I still don’t understand how to solve my
problem.
I have Publication, Picture, File classes
A Publication can be related (a one way relation, like a www link) with
another Publication, Picture or File
I tried this :
Publication :
has_many :related_elements, :dependent => :destroy, :foreign_key =>
:publication_id
has_many :related, :through => :related_elements, :as => :linked,
:source => :publication
RelatedElement :
belongs_to :publication
And migrate as
create_table :related_elements do |t|
t.integer :linked_id
t.string :linked_type
t.integer :publication_id
end
When I do
a_publication.related[0] = another_publication
a_publication.save!
I would expect the related_elements table beeing updated with
publication_id = the id of a_publication
linked_id = the id of another_publication
linked_type = the class name ‘Publication’
But nothing happen… And I must confess that I’m pretty sure my
has_many are totally wrong
All this stuff is really too complex for me, so your help will be
greatly appreciated !! Thanks