I am trying to create a model for a ruby on rails project that builds relationships between different words. Think of it as a dictionary where the ‘Links’ between two words shows that they can be used synonymously. My DB looks something like this:
Words ---- id Links ----- id word1_id word2_id
How do I create a relationship between two words, using the link-table. I’ve tried to create the model but was not sure how to get the link-table into play:
class Word < ActiveRecord::Base has_many :synonyms, :class_name => 'Word', :foreign_key => 'word1_id' end
In general, if your association has suffixes such as 1 and 2, it’s not set up properly. Try this for the Word model:
Link model:
Tables: