[Dbix-class] Joins with circular relations

Matt S Trout dbix-class at trout.me.uk
Thu Oct 4 22:04:06 GMT 2007


On Thu, Oct 04, 2007 at 10:16:41AM +0200, Bernhard Weisshuhn wrote:
> On Wed, Oct 03, 2007 at 11:51:05PM +0100, Matt S Trout <dbix-class at trout.me.uk> wrote:
> 
> > On Wed, Oct 03, 2007 at 06:17:54PM +0200, Bernhard Weisshuhn wrote:
> > >
> > > [...]
> > > 
> > >   SELECT
> > >     translatedwords.translatedword
> > >   FROM
> > >     userwords
> > >     JOIN users ON (users.user = userwords.user)
> > >     JOIN translatedwords ON (
> > >         translatedwords.language    = users.language AND
> > >         translatedwords.englishword = userwords.englishword
> > >     )
> > >   WHERE
> > >     userwords.user='someuser';
> > 
> > Just move on or other of the two cond in the second join into the
> > WHERE clause.
> 
> OIC, thanks! So it's more of an SQL::Abstract issue then.

Well, it's a mixture of SQLA and DBIC's use of it. We're gonna have a go
at refactoring SQLA and then taking advantage of the new features in DBIC for
09 or so.
 
> So I came up with this one:
> 
>   my $userwords = $schema->resultset('Translatedwords')->search(
>     {
>       'user.user' => 'someuser',
>       'me.language' => \'= user.language'
>     },
>     {
>       join => { englishword => { userwords => 'user' } }
>     }
>   );
> 
> Is there a way to avoid the ugly scalar reference?

Not currently, sorry.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list