CREATE TABLE segments ( id serial PRIMARY KEY, name character varying(100) NOT NULL, status integer NOT NULL ); CREATE TABLE segmentlinks ( id serial PRIMARY KEY, parent_seg_id integer NOT NULL, child_seg_id integer NOT NULL, sequence_no integer NOT NULL ); class Segmentlink < ActiveRecord::Base has_many :segments, :primary_key => "parent_seg_id" end class Segment < ActiveRecord::Base belongs_to :segmentlink end