I’m trying to model the following kind of relationship in my
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
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
and in the model:
class Topic < ActiveRecord::Base
: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
I can’t affect it neither during <<'ing of related_topics, or any other
E.g. when I do:
tp = Topic.find(1)
tp.related_topics.find(1).similarity = 5
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.