Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 84070
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: chen.yack [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.08099_03
Fixed in: (no value)



Subject: DBIx::Class::Relationship::Base self and foreign alias reversed
package 'PeSystem::Schema::Result::Preplan::Preplan'; ... __PACKAGE__->has_many( "preplan_plan_action_stars", "PeSystem::Schema::Result::Preplan::PlanActionStar", sub { my $args = shift; use Data::Dumper; $Data::Dumper::Maxdepth=4; print Dumper $args; return({ "$args->{foreign_alias}.sid" => { -ident => "$args->{self_alias}.id" }, "$args->{foreign_alias}.stype" => "preplan", }, $args->{self_rowobj} && { "$args->{foreign_alias}.sid" => $args->{self_alias}->id, "$args->{foreign_alias}.stype" => "preplan", }) }, { cascade_copy => 0, cascade_delete => 1 }, ); 1; when use this code my $preplan = $self->app->schema->resultset('Preplan')->find(1); my $x = $preplan->preplan_plan_action_stars->count; the exception throwed is following: PeSystem::Schema::Result::Preplan::Preplan::preplan_plan_action_stars(): Can't locate object method "id" via package "preplan_plan_action_stars" (perhaps you forgot to load "preplan_plan_action_stars"?) at /home/admin/perl_pesystem/script/../lib/PeSystem/Schema/Result/Preplan/Preplan.pm line 216. ====== ========== i debug into the code , then found that the reverse of the $args->{self_alias} and $args-> {foreign_alias} is in : /usr/local/lib/perl5/site_perl/5.16.2/DBIx/Class/ResultSource.pm, line 1663 sub _resolve_condition 1666 my $obj_rel = !!blessed $for; 1667 1668 if (ref $cond eq 'CODE') { 1669 my $relalias = $obj_rel ? 'me' : $as; 1670 1671 my ($crosstable_cond, $joinfree_cond) = $cond->({ 1672 self_alias => $obj_rel ? $as : $for, why test blessed or not of $for ? i think whether the $obj_ref blessed or not , $self_alias should be $for, and $foreign alias should be $as, hope fix this bug :)
Subject: Re: [rt.cpan.org #84070] DBIx::Class::Relationship::Base self and foreign alias reversed
Date: Wed, 20 Mar 2013 03:23:16 +1100
To: chinaxing via RT <bug-DBIx-Class [...] rt.cpan.org>
From: Peter Rabbitson <ribasushi [...] cpan.org>
On Tue, Mar 19, 2013 at 12:03:39PM -0400, chinaxing via RT wrote: Show quoted text
> return({ > "$args->{foreign_alias}.sid" => { -ident => "$args->{self_alias}.id" }, > "$args->{foreign_alias}.stype" => "preplan", > }, $args->{self_rowobj} && { > "$args->{foreign_alias}.sid" => $args->{self_alias}->id,
^^^^^^^^^^^^^^^^ This makes no sense Show quoted text
> "$args->{foreign_alias}.stype" => "preplan", > })
foreign_alias and self_alias are *strings*. The aliases given to the left and right side of the join. You probably meant self_rowobj...? Cheers
Rejecting ticket as "user misread documentation". Feel free to reopen if I missed something.