binary_luigi binary_luigi - 7 months ago 13
Perl Question

How can you modify a DBIx::Class::Row in place?

Using DBIx::Class::ResultSet is it possible to make changes to the results in memory as attempted below?

my @results = $self->search(...);

for my $result (@results) {
my $row = {$result->get_columns};
$row->{fieldname} = 'something else';
}

return @results;

Answer

A column accessor is generated by DBIx::Class for every column you define. It can be used both as a reader

my $value = $row->columnname;

and as a writer

$row->columnname('new value');