[Dbix-class] Result column accessors not called with update method?

Henry Van Styn vanstyn at cpan.org
Mon Jun 16 15:49:21 GMT 2014


And, yes, for the case of the ResultSet you have to handle it separately… to force everything through the same machinery, in your resultset class you can override ‘update’ to call ‘update_all':

  sub update { (shift)->update_all(@_) }

Not that it is necessarily a good idea to do that… It will wipe away the performance benefit of $Rs->update, which performs a single update query (you can’t have it both ways). So you should probably just not call $Rs->update, and use update_all to begin with, which calls update for each row…

Henry 


On Jun 16, 2014, at 11:40 AM, Henry Van Styn <vanstyn at cpan.org> wrote:

> Do it all in update()… Something like:
> 
> 
>  sub update {
>    my ($self, $columns) = @_;
>    $self->set_inflated_columns($columns) if ($columns);
> 
>    if($self->collection_date > $now) { … }
> 
>   # Other logic, etc ….
> 
>    return $self->next::method;
>  }
> 
> 
> Henry
> 
> 
> On Jun 16, 2014, at 7:11 AM, Adam Witney <awitney at sgul.ac.uk> wrote:
> 
>> Hi,
>> 
>> I wrote an accessor on a date column within my Result class, to check if the date supplied is not in the future.
>> 
>> This works fine if I use it like so:
>> 
>> $result->collection_date('1/1/2014');
>> 
>> however this doesn't work if I update like so:
>> 
>> $result->update({ collection_date => '1/1/2014' });
>> 
>> This appears to be as documented:
>> 
>> http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#update
>> 
>> But I wondered, is there a way round this or if not, where is the best place to put this kind of validation that will work no matter which update approach I take?
>> 
>> Thanks for any help
>> 
>> Adam
>> 
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
> 




More information about the DBIx-Class mailing list