Personally, I find it's easier to use DBIx::Class for the little things too... most of the work is just in creating the class, but once it's created things are so easy.

Take this, for example:

my $sth = $dbh->prepare("SELECT * FROM table");
$sth->execute();

while (my $row = $sth->fetchrow_hashref()) {
        # Do stuff
        $dbh->do("UPDATE table SET somecol=? WHERE someothercol=?",
                $var1, $var2);B
}


#### Boring :(


Now this...

my $rs = $schema->resultset('table')->search;
while (my $row = $rs->next) {
        # Do stuff
        $row->somecol($var1);
        $row->update;
}


Now, i'm pretty drunk now, and i was able to write the second one without correcting typo's...the first one i had to keep going back :D That's gotta be some indication!






On Thu, 3 Aug 2006, Anthony Gardner wrote:

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 <[EMAIL PROTECTED]> 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
_______________________________________________
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]/

Reply via email to