[Dbix-class] update_or_insert from hash reference

John Li johnli at accessmedia.tv
Wed May 24 00:55:15 CEST 2006

I don't mind to write the patch, Matt. Do you have something like
ubversion to get me started?


John (Zhuang) Li

-----Original Message-----
From: dbix-class-bounces at lists.rawmode.org
[mailto:dbix-class-bounces at lists.rawmode.org] On Behalf Of Matt S Trout
Sent: Tuesday, May 23, 2006 3:50 PM
To: dbix-class at lists.rawmode.org
Subject: Re: [Dbix-class] update_or_insert from hash reference

John Li wrote:
>> Will it use the primary key as declared in Users.pm? Or
>> should I have to pass it as an extra attribute to the search
>> call? (i.e. as in ->search( hashRef, { key => user_id } ) )
>> I've already tried this and it didn't work ... but maybe I'm
>> doing something wrong (again).
> my $user = $dbix->resultset('Users')->update_or_create($hashref);
> :)
> Just curious, Matt, why delete doesn't work the same way?
> i.e. $dbix->resultset('Users')->delete($hashref) instead of
> $dbix->resultset('Users')->search($hashref)->delete?

update_or_create is a row-level operation that gets performed in the 
context of a resultset; $rs->delete is a resultset-level operation. I 
don't see any particular reason not to support ->delete($cond) though 
(probably by just expanding it internally to ->search($cond)->delete), 
but somebody else gets to write up the test cases and patch :)

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/

More information about the Dbix-class mailing list