[Dbix-class] Adding an additional custom join parameter

Andrew Beverley andy at andybev.com
Wed Dec 11 07:25:18 GMT 2013


On Wed, 2013-12-11 at 05:54 +1100, neil.lunn wrote:
> On 9/12/2013 12:41 PM, Andrew Beverley wrote:
> > My database has a table that has 2 other "has many" tables related to
> > it, best described by this diagram:
> >
> > http://files.andybev.com/schema.png
> >
> > I want to select from the "task" table, joining both other tables at the
> > same time. In order for the joins to work correctly, in raw SQL I would
> > use 2 conditions for the join of the "issue" table:
> >
> > "issues.task_id = me.id AND issues.site_id = site_tasks.site_id"
> >
> > However, by default, DBIx::Class only uses the first condition, as per
> > my relationship definitions. How can I add the second condition?
> 
> Argh. I Promised to be less angry next year and not be an older version 
> of MST. <Less hair you know>
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Relationship.pm 
> <http://search.cpan.org/%7Eribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Relationship.pm>
> 
> and of course:
> 
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Manual/Joining.pod 
> <http://search.cpan.org/%7Eribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Manual/Joining.pod>
> 
> So RFTM.

Believe me, I spent several hours doing exactly that, and my questions
were based on what I read. So if I'm asking questions that are already
answered, then it's not clear to me. I can only apologise for my
misunderstanding.

I post to mailing lists as a last resort only. As a result, I've had
some good suggestions for different ways of doing it, which I'll be
looking at - thanks to all those folks.

>  You need to define your joins in you classes. Schema loader 
> stuff will only do what you reasonably, intelligently put in your 
> initial DDL on the SQL side.

As per my previous posts, I'll redesign my database, based on the
previous helpful suggestions.

Thank you,

Andy





More information about the DBIx-Class mailing list