[Dbix-class] Bug in DBIx::Class::ResultSource::remove_columns ?
Oleg Pronin
syber.rus at gmail.com
Mon Jan 12 23:24:40 GMT 2009
Maybe i misunderstood something but i suppose there is a bug in
remove_columns.
DB<14> x
$this->columns
0 'id'
...
16 'logo_small'
17 'logo_mid'
18 'logo_full'
19 'screenshots'
20 'data'
21 'logo'
$this->remove_column($c); # $c =3D 'logo';
DB<15> x
$this->columns
0 'id'
...
16 'logo_mid'
17 'logo_full'
18 'screenshots'
19 'data'
It removed 'logo_small' as well.
In DBIx::Class::ResultSource:
sub remove_columns {
my ($self, @cols) =3D @_;
return unless $self->_ordered_columns;
my $columns =3D $self->_columns;
my @remaining;
foreach my $col (@{$self->_ordered_columns}) {
push @remaining, $col unless grep(/$col/, @cols);
}
foreach (@cols) {
delete $columns->{$_};
};
$self->_ordered_columns(\@remaining);
}
What is this: "grep(/$col/, @cols);" and what for?
Doc says
"$table->remove_columns(qw/col1 col2 col3/);
Removes columns from the result source."
Not "Removes all columns that looks like" :-)
Patch:
sub remove_columns {
my ($self, @to_remove) =3D @_;
return unless my @ordered =3D $self->_ordered_columns;
my $columns =3D $self->_columns;
delete $columns->{$_} for @to_remove;
my %to_remove =3D map {$_ =3D> 1} @to_remove;
$self->_ordered_columns([grep {!$to_remove{$_}} @ordered]);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090113/3af=
09364/attachment.htm
More information about the DBIx-Class
mailing list