[Dbix-class] update_or_insert from hash reference

Matt S Trout dbix-class at trout.me.uk
Wed May 24 00:49:59 CEST 2006


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 :)



More information about the Dbix-class mailing list