Greetings. I am new to RoR, and to programming in general, so I apologize if the solution is trivial.
My goal is to keep track of the 5 most common "Tag_Relationships" in a tagging scheme. This would let me ask such things as "what tag accompanies the tag 'computer' most often, second most often" etc.. I figured this might be easier than storing an Array with the last_five per Agile Web Development edition 2. I chose to use the acts_las_list feature.
my question involves two models
Tag ... has_many :tag_relationships, :order => :position validates_uniqueness_of :name
Tag_Relationship belongs_to :tag, :foreign_key => 'related_tag_id' acts_as_list :scope => :tag validates_uniqueness_of :tag_id, :scope => :related_tag_id
Questions. Something looks fishy to me in the belongs_to for Tag_Relationships. I had to do this to get it to work, but really, the tag_relationship belongs to the original tag, not the referred tag. What is the correct way to use has_many / belongs_to in this case? I would like to be able to do the following
t = Tag.find(1) trs = t.tag_relationships
and then iterate over the collection and get the name for each referred tag. My tag_relationships table is as follows
create_table "tag_relationships", :force => true do |t| t.column "tag_id", :integer t.column "related_tag_id", :integer t.column "position", :string #ranking for this particular tag t.column "relationships_count", :integer, :default => 1 #number of times this relationship has been recorded end
Thanks in advance
John