[Dbix-class] Extra columns in data for update/create

Trevor Phillips trevor.phillips at gmail.com
Fri Mar 13 03:36:26 GMT 2009


On Fri, Mar 13, 2009 at 11:59 AM, Jason Kohles <email at jasonkohles.com> wrote:
> On Mar 12, 2009, at 10:22 PM, Trevor Phillips wrote:
>
>> Is there an easy and efficient way to either tell methods like create
>> to ignore extra columns passed in, or to filter %Data to only include
>> columns in the table?
>>
> I don't know about efficient, but this is how I do it...
>
> package MyApp::DB::Result;
> use parent 'DBIx::Class';
> # ...
> sub absorb {
>    my ( $self, $in ) = @_;
>
>    $self->update( {
>        map { ( $_ => $in->{ $_ } ) }
>        grep { $self->has_column( $_ ) }
>        keys %{ $in }
>    } );
> }

Aha! I was doing something similar to filter the data - but was
manually specifying a columns filter. I missed has_column. Thanks!

Doing it as a method of the class is neat, too, although it would be
nice to have this sort of functionality built in to DBIx::Class,
either as an alternate method to update, or as an option to update.
ie; something like:
  $self->update($Data, { 'ignore_extra_cols' => 1 });

-- 
Trevor Phillips  - http://dortamur.livejournal.com/
"On nights such as this, evil deeds are done. And good deeds, of
course. But mostly evil, on the whole."
      -- (Terry Pratchett, Wyrd Sisters)



More information about the DBIx-Class mailing list