From: Todd Benson Date: 2008-08-13T01:47:39+09:00 Subject: Re: store data in join table On Tue, Aug 12, 2008 at 6:00 AM, Ganesh Kumar wrote: > Hi, > I have one join table called > > for example "students_subjects" and i am having relationship like > in > student model > :has_many=>subjects ,:through=>students_departments > > in > subjects table > :has_many=>students ,:through=>students_departments > > i need to store data in join table > join table columns > > 'id' 'student_id' 'subject_id' > > how can i store plz reply if anybody knows solution..... I don't know why people pick those type of names for tables, but a similar schema is... create table people ( account varchar not null primary key ); create table collection ( team varchar not null primary key ); create table membership ( account varchar not null references people (account), team varchar not null references collection (team), primary key (account, team) ); You'd want to add check constraints in a real database, along with other info, of course. I'm pretty sure ActiveRecord will force you to use an arbitrary ID field with the join table. I haven't used ActiveRecord in a while, but IIRC, I think I circumvented that annoyance by using "unique" instead of "primary key" for my multiple keys in join tables. The ActiveRecord::Base class does allow you to define your own primary keys (unless they're multiple). hth, Todd