[Dbix-class] Patch to ResultSource.pm

Jonas Alves jonas.alves at co.clix.pt
Mon Feb 27 03:46:33 CET 2006


Hello list,

I need to do a select like this:

SELECT me.foo, image.bar FROM article me LEFT JOIN article_image image 
ON ( image.article_id = me.id AND image.order = 1 ) LEFT JOIN image 
image_2 ON ( image_2.id = image.image_id );

So in my article class i created this relationship:

__PACKAGE__->add_relationship(image => 'article_image', 
{'foreign.article_id' => 'self.id', 'foreign.order' => 1},
   { accessor => 'single', join_type => 'LEFT' });

and in my article_image class this relationship:

__PACKAGE__->belongs_to(image  => 'Image', 'image_id', {join_type => 
'LEFT'});

But then i get this error message:

DBIx::Class::ResultSet::search(): Invalid rel cond val 1

Here goes a litle patch to make my query possible.

399a400
 >       my $string = 0;
402c403
<       $v =~ s/^self\.// || $self->throw_exception("Invalid rel cond 
val ${v}");
---
 >       $v =~ s/^self\.// || ($string = 1);
408c409
<         $ret{"${as}.${k}"} = "${for}.${v}";
---
 >         $ret{"${as}.${k}"} = $string ? $v : "${for}.${v}";



More information about the Dbix-class mailing list