Hi, folks!
I'm trying to model the following kind of relationship in my application:
Each Topic has many related Topics. The relationship is characterised by "similarity" parameter.
That's what I have in DB:
create_table "topics" do |t| t.column "name" :string end
create_table "related_topics" do |t| t.column "topic_id", :integer, :null => false t.column "related_topic_id", :integer, :null => false t.column "similarity" :integer end
and in the model:
class Topic < ActiveRecord::Base has_and_belongs_to_many :related_topics, :class_name => "Topic", :join_table => "related_topics", :association_foreign_key => "related_topic_id", :foreign_key => "topic_id"
What is bad about this reference is that the similarity parameter is unaccessible! I can't affect it neither during <<'ing of related_topics, or any other way.
E.g. when I do: tp = Topic.find(1) tp.related_topics.find(1).similarity = 5 tp.save
the similarity does not save.
I guess I should use join models and :through, but I have no idea how to access similarity parameter in that case as well.
Please point me at any solutions to the problem. Thank you.