Error with +columns

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
mpm
Reply | Threaded
Open this post in threaded view
|

Error with +columns

mpm
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;

If the search returns only one result, IT WORKS FINE. But if it returns more than one, the following error happens:

SELECT me.m_id, me.t_id, tD.o_id FROM t2m_id me  JOIN tD ON tD.T_ID = me.t_id LEFT JOIN g ON g.o_id = tD.o_id LEFT JOIN sp ON sp.sp_c = g.sp_c WHERE ( ( me.m_id = ? AND sp.is = ? ) ) GROUP BY me.t_id: '452497', 'y'
[error] No such column 'tD.o_id' at /usr/local/share/perl/5.10.1/DBIx/Class/Schema.pm line 1078
        DBIx::Class::Schema::throw_exception('weight=HASH(0xc7241f0)', 'No such column \'tD.o_id\'') called at /usr/local/share/perl/5.10.1/DBIx/Class/ResultSource.pm line 1968
        DBIx::Class::ResultSource::throw_exception('DBIx::Class::ResultSource::Table=HASH(0xc721248)', 'No such column \'tD.o_id\'') called at /usr/local/share/perl/5.10.1/DBIx/Class/Row.pm line 1445
        DBIx::Class::Row::throw_exception('portfolio::Model::weight::T2m_id=HASH(0xcd2cae8)', 'No such column \'tD.o_id\'') called at /usr/local/share/perl/5.10.1/DBIx/Class/Row.pm line 621

I think it has to do with the +columns

How can I correct it? and why it started to happen now??
Reply | Threaded
Open this post in threaded view
|

Re: Error with +columns

Peter Rabbitson-2
On Fri, Dec 14, 2012 at 12:48:22PM -0800, mpm wrote:
> I am getting an error, that was not happening before:

What version were you using before, and what version are you using now.

_______________________________________________
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@...
mpm
Reply | Threaded
Open this post in threaded view
|

Re: Error with +columns

mpm
I don't really know how to check the version


2012/12/14 Peter Rabbitson <[hidden email]>
On Fri, Dec 14, 2012 at 12:48:22PM -0800, mpm wrote:
> I am getting an error, that was not happening before:

What version were you using before, and what version are you using now.


_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: Error with +columns

Dwalu Khasu
Heya Paula,

Try this:  perl -e 'use DBIx::Class; print "$DBIx::Class::VERSION\n"'

Best,
Dwalu

Dwalu Khasu
[hidden email]
415.763.7637
Technologist / Social Entrepreneur



On Sat, Dec 15, 2012 at 12:47 AM, Paula <[hidden email]> wrote:
I don't really know how to check the version


2012/12/14 Peter Rabbitson <[hidden email]>
On Fri, Dec 14, 2012 at 12:48:22PM -0800, mpm wrote:
> I am getting an error, that was not happening before:

What version were you using before, and what version are you using now.


_______________________________________________
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@...


_______________________________________________
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@...
mpm
Reply | Threaded
Open this post in threaded view
|

Re: Error with +columns

mpm
thanks!
the result of this was 0.08195

2012/12/15 Dwalu Khasu <[hidden email]>
 perl -e 'use DBIx::Class; print "$DBIx::Class::VERSION\n"'


_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: Error with +columns

Peter Rabbitson-2
In reply to this post by mpm
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

_______________________________________________
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@...