[Dbix-class] update_or_create and add_unique_constraint

Nathan Kurz nate at verse.com
Fri Jul 28 06:47:21 CEST 2006


On Fri, Jul 28, 2006 at 12:16:52AM -0400, Daniel Westermann-Clark wrote:
> On 2006-07-27 20:13:17 -0600, Nathan Kurz wrote:
> > 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.
> 
> This is true.  I've added a fix (and test) for this to trunk, which
> will be in the next release.
> 
> http://dev.catalyst.perl.org/trac/bast/changeset/2643
> 
> However, it's important to note that DBIx::Class cannot currently
> update a row based on a unique constraint.  You'll get an error about
> not being able to safely update the row on a PK-less table.
> 
> So for now you'll have to add a primary key to your table.

Thank you for the amazingly quick fix, and for the warning.  Since I'm
using SQLite, I've changed my Schema to declare ROWID (the built in
primary key) as the primary key, and updates seem to be working.

---------------------------------------------------------------------
package App::Model::DB::Schema::Rating;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core PK::Auto/);
__PACKAGE__->table('rating');
__PACKAGE__->add_columns(qw/ROWID uid iid score flags/);
__PACKAGE__->set_primary_key(qw/ROWID/);
__PACKAGE__->add_unique_constraint(uid_iid => [ qw/uid iid/ ]);
---------------------------------------------------------------------

Thanks!

--nate




More information about the Dbix-class mailing list