Store data in join table

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.....

···

--
Posted via http://www.ruby-forum.com/.

You want the RubyOnRails mailing-list.

Anyways, just add the column to your join table, you're already using
has_many :through, which is intended for join tables with additional
data on the relationship.

Michael Guterl

···

On Tue, Aug 12, 2008 at 7:00 AM, Ganesh Kumar <gani_chinta@yahoo.com> 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

···

On Tue, Aug 12, 2008 at 6:00 AM, Ganesh Kumar <gani_chinta@yahoo.com> 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.....

On Tue, Aug 12, 2008 at 11:50 AM, Todd Benson

I don't know why people pick those type of names for tables

By that I meant the tablea_tableb nomenclature, which seems to be what
all the business graduates are learning nowadays.

I would suggest using collective nouns when possible, followed by
plural nouns if not.

My favorite database faux pas is the use of numbers in table names.

Rant over...

Todd