[Dbix-class] Error with +columns
Peter Rabbitson
rabbit+dbic at rabbit.us
Tue Dec 18 08:18:04 GMT 2012
On Fri, Dec 14, 2012 at 12:48:22PM -0800, mpm wrote:
> I am getting an error, that was not happening before:
>
> my $where_o={};
> my $attr_o={};
> my @og;
> $where_o->{'me.m_id'}= $m_id;
> $where_o->{'sp.is'}='y';
> push @{ $attr_o->{join} }, {'tD' => {'g' => 'sp'}};
> $attr_o->{group_by}='me.t_id';
> $attr_o->{'+columns'}= [ qw/tD.o_id/];
> my
> $ogs=$c->model('weight::T2m_id')->search($where_o,$attr_o);
> while (my $rs_ogs = $ogs->next()) {
> my $o_group=$rs_ogs->get_column('tD.o_id');
> push @o_groups,$o_group;
> }
> $c->stash->{o_groups}=\@o_groups;
This code is extremely weird, and I am not sure how old of a DBIC you
had *before* upgrading that would allow it to work. In fact I honestly
have no idea how did get_column('foo.bar') ever work for you - is there
perhaps more code that you are not showing us? On any DBIC version in
*at least* the past 4-5 years this would throw with "no such column
tD.o_id"
In any case, the above is better/clearer written as:
$c->stash->{o_groups} = [
$c->model('weight::T2m_id')->search(
{
'me.m_id' => $m_id,
'sp.is' => 'y',
},
{
join => {'tD' => {'g' => 'sp'}},
distinct => 1,
}
)->get_column('tD.o_id')->all
];
Note - the get_column I used[1] is *different* than the get_column you
used[2].
Let us know if you have further questions.
Cheers
[1] https://metacpan.org/module/DBIx::Class::ResultSet#get_column
[2] https://metacpan.org/module/DBIx::Class::Row#get_column
More information about the DBIx-Class
mailing list