[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

store data in join table

Ganesh Kumar

8/12/2008 11:00:00 AM

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

3 Answers

Michael Guterl

8/12/2008 11:57:00 AM

0

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

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

Todd Benson

8/12/2008 4:48:00 PM

0

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

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

Todd Benson

8/12/2008 6:18:00 PM

0

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