[Dbix-class] Newbie to ORM and DBIx (pls help)
David Kamholz
davekam at pobox.com
Tue Aug 1 18:35:47 CEST 2006
Unless there is some compelling reason to do otherwise, you should
make the primary key of school_attendees PRIMARY KEY (attendee_id,
school_id). But this is a minor issue, DBIx::Class doesn't really
care as long as the classes are in sync with the database.
Anyway, here's probably what you should be doing:
package DB::MyTestSchema::SchoolAttendee;
__PACKAGE__->belongs_to( school => 'DB::MyTestSchema::School',
'school_id' )
__PACKAGE__->belongs_to( student => 'DB::MyTestSchema::Student',
'attendee_id' );
package DB::MyTestSchema::Student;
__PACKAGE__->has_many( school_attendees =>
'DB::MyTestSchema::SchoolAttendee', 'attendee_id' );
__PACKAGE__->many_to_many( schools => 'school_attendees', 'school' );
package DB::MyTestSchema::School;
__PACKAGE__->has_many( school_attendees =>
'DB::MyTestSchema::SchoolAttendee', 'school_id' );
__PACKAGE__->many_to_many( students => 'school_attendees', 'student' );
Dave
More information about the Dbix-class
mailing list