[Dbix-class] chained 'search' then 'update'

Matt Lawrence matt.lawrence at ymogen.net
Wed Mar 5 11:01:20 GMT 2008


Matt Lawrence wrote:
> Angel Kolev wrote:
>> Hi, all.
>>
>> I have a table with fields 'id' and 'status'. Status is ENUM field 
>> with values 'active' and 'backup'. I need somethink like(i use dbic 
>> in catalyst):
>>
>> my $rs = $c->model('ModelDB::CheckMap')->search({id => 
>> $id})->update('status','backup');
>> $rs->create({%params});
>>
>> I have to change the status of all old fields for id $id to 'backup' 
>> then create new fields. Can i change this status in one pass like 
>> example above?
>>
> As far as I can see, the only problem with the line you have is that 
> update expects a hashref.
>
> Matt
>
Oops, also, update won't return the ResultSet, so $rs won't be what you 
expect on the second line.

my $rs = $c->model('ModelDB::CheckMap');
$rs->search({ id => $id })->update({ status => 'backup' });
$rs->create(\%params);

Matt



More information about the DBIx-Class mailing list