[CDBI] Fwd: find_or_create() barfs with constraints

Aaron Turner aturner at musecurity.com
Tue Aug 2 19:54:15 BST 2005

I'm looking to insert a record in table if it doesn't already exist.   
I've also created a unique key (across two columns) to prevent other  
access not via Class::DBI from causing problems.

The issue seems however that when I do a Object->find_or_create 
({ col1 => 'value', col2 => 'value'}) I get an error when it  
apparently tries to insert a duplicate record.

For what it's worth:

Class::DBI 0.96
DBD::Pg 1.43
Class::DBI::Pg 0.6
PostgreSQL 8.0.3

The offending code:
$VT = Mu::VariantType->find_or_create({ name => $variant,
         suite_typeID => $ST->id });

My object:
package Mu::VariantType;
use lib '..';
use base 'Mu::DBI';
use Mu::MutationVariant;
use Mu::VariantCategory;
use Mu::SuiteType;
use Mu::TestGroupVariant;

__PACKAGE__->columns(All => qw/variant_typeID suite_typeID  
next_mutationID name description/);

# Note that there is a unique key over suite_typeID/name

#_PACKAGE__->has_many('mutations', Mu::MutationVariant =>  
'variant_typeID' );
__PACKAGE__->has_many(categories => [ Mu::VariantCategory =>
     'category_typeID' ]);
__PACKAGE__->has_a(suite_typeID => 'Mu::SuiteType');
__PACKAGE__->has_many(test_groups => [ Mu::TestGroupVariant =>  
'test_groupID' ]);


Note that Mu::DBI's base is Class::DBI::Pg.

Aaron Turner, Sr. Security Engineer                        
<aturner at musecurity.com>

More information about the ClassDBI mailing list