[Dbix-class] update_or_create and add_unique_constraint

Nathan Kurz nate at verse.com
Fri Jul 28 04:13:17 CEST 2006


I'm trying to use DBIx-Class-0.07000 under Catalyst.  Most things are
working, but for the first time I'm trying to use update_or_create()
on a table without a primary key, and I'm flailing.  I can't tell if
the problem is bugs or my unfamiliarity with DBIx.

-------------------------------------------------------
package App::Model::DB::Schema::Rating;
use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('rating');
__PACKAGE__->add_columns(qw/uid iid score flags/);
__PACKAGE__->add_unique_constraint(uid_iid => [ qw/uid iid/ ]);

--------------------------------------------------------
$c->model('DB::Rating')->update_or_create({
	   uid => $uid,
	   iid => $id,
	   score => $score,
	   flags => $flags,
	  }, { key => 'uid_iid' });
--------------------------------------------------------

Caught exception in App::Controller::Import->index
 "DBIx::Class::ResultSet::update_or_create(): Can't find unless a
  primary key or unique constraint is defined"

----------------------------------------------------------

I've tried both with an automatically named constraint, and with a
generated one.  I've tried specifying a key attribute to
update_or_create, and letting it be found automatically.  Nothing I've
tried yet has worked.

Glancing at the source, it looks like
DBIx::Class::ResultSet::update_or_create() is accepting both $cond and
$attr, but only passes $cond on to find.  And it looks like
DBIx::Class::ResultSet::find() will use unique contraints if passed
them, but only searches for primary columns if given nothing.


Thanks!

Nathan Kurz
nate at verse.com




More information about the Dbix-class mailing list