store data in join table

G

Ganesh Kumar

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

Michael Guterl

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

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
 
T

Todd Benson

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
 
T

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,660
Latest member
vidotip479

Latest Threads

Top