[Dbix-class] find_or_create_related not working in 8.003

Steve Caldwell info-dbic at caldwellhb.com
Wed Jul 18 17:44:47 GMT 2007

When I upgraded from 7.006 to 8.003, the following (illustrative) code 
stoppped working:

package My::Schema::Zoo;
use strict;
use base qw(DBIx::Class);
__PACKAGE__->add_columns(qw(zoo_id name));
__PACKAGE__->has_many(animals => 'My::Schema::Animal', 'zoo_id');

package My::Schema::Animal;
use strict;
use base qw(DBIx::Class);
__PACKAGE__->add_columns(qw(animal_id zoo_id type));
__PACKAGE__->belongs_to(zoo => 'My::Schema::Zoo', 'zoo_id');

    one_type_per_zoo => [ qw(zoo_id type) ],


my $zoo_rs = $schema->resultset('Zoo')->search();

while (my $zoo = $zoo_rs->next) {


sub populate {
    my $zoo = shift;
    foreach my $type(qw(lion tiger elephant)) {
        my $animal = $zoo->find_or_create_related(
            { type => $type  },



- the error I get is 
"DBIx::Class::Relationship::Base::find_or_create_related(): Can't locate 
DBI object method "last_insert_rowid" via package "DBD::mysql::db" at 
/usr/local/share/perl/5.8.8/DBIx/Class/Storage/DBI.pm line 1173."

- the error only occurs if it needs to create an Animal - if all the 
corresponding rows already exist in tblanimal, it works fine.

- this code works fine:

    my $zoo = $schema->resultset('Zoo')->find(1);

Is there something wrong with my code that was allowed to work in 7.006 
but not in 8.003?  Is anyone else having this problem?  I've tried it on 
two different OS's (Ubuntu, OS X), and seen the same problem.


More information about the Dbix-class mailing list