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

Henry Van Styn vanstyn at cpan.org
Mon Jun 16 15:40:08 GMT 2014


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