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 :)