[Dbix-class] Auto-joins

Matt S Trout dbix-class at trout.me.uk
Thu Mar 30 15:07:38 CEST 2006


Darren Duncan wrote:
> At 09:45 +0200 30/3/06, Yuval Kogman wrote:
>> On Wed, Mar 29, 2006 at 22:28:09 -0300, Nilson Santos Figueiredo Junior wrote:
>>>  While reading the documentation I couldn't find any reference
>>>  regarding DBIx::Class performing auto-joins. You'd always need to
>>>  explicitely specify them.
>>>
>>>  Is there any reason preventing this from being implemented so that
>>>  code like this:
>>>
>>>  my $rs = $schema->resultset('CD')->search(
>>>      {
>>>        'artist.name' => 'Bob Marley'
>>>      }
>>>  );
>>>
>>> would work fine?

That wouldn't need to be ambigious provided you use the relationship name 
rather than the table name.

>>
>> SQL::Abstract is not modular enough... Please join me on irc at
>> around 18:00 GMT as I'm suffering from this too and want to fix it
>> =)

Right. I made this sort-of work in Sweet, but it was a nasty, fragile hack 
(including the fine joy of regexing the generated SQL afterwards because it 
didn't provide me anywhere at all to hook the key part of IS NULL clauses). 
I've politely refused to visit anything that horrific on the DBIC internals, 
on the grounds that a little extra typing is a lot better than flaky automagic.

> One way to fix it is to name your table columns such that they lend 
> themselves to using natural joins.  Then you can simply say 'name' 
> rather than 'artist.name', and it will work correctly and 
> unambiguously.  Those kinds of joins are called 'natural' for a 
> reason. -- Darren Duncan

That still won't help unless the ORM knows to add the JOIN artist to the
FROM part of the SQL statement in the first place, which is what we're 
discussing here.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list