[Dbix-class] Newbie to ORM and DBIx (pls help)

Anthony Gardner cyclewood_ltd at yahoo.co.uk
Thu Aug 3 12:17:28 CEST 2006


Thank you for that gentlemen. I had a play with it last night and got it working but the main thing is ..... I understand how it's working.
 
 As with everything new, is there a time to use it and a time to just use DBI (for example)?
 
 Is ORM only useful for large projects or would you recommend trying to fit it in to everything you do with a DB?

David Kamholz <davekam at pobox.com> wrote: 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

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/


 		
---------------------------------
 Try the all-new Yahoo! Mail . "The New Version is radically easier to use" – The Wall Street Journal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060803/859958f2/attachment.htm 


More information about the Dbix-class mailing list