Please help.
I have a self referencing model and want the foreign key to refer to a non-primary key that is scoped.
In the list table, I have a sequence_id column which contains the incremental id of the list that is only unique in a listset. Meaning the same sequence_id can be seen for list of another listset. However, as this sequence_id is not unique throughout the table, I didn't make it a primary key.
How do I achieve the self-referencing relation using this non-primary key?
Thank you very much.
Model:
Class Listset
has_many :lists, :dependent => :delete_all
has_many :items, :through => :lists
end
Class List
belongs_to :listset
belongs_to :parentList, :class_name => "List"
has_many :childList, :class_name => "List", foreign_key => "parent"
has_many :items, :dependent => :delete_all
end
Class item
belongs_to :list
end