[CDBI] Using Left/Right joins

Matt S Trout dbix-class at trout.me.uk
Tue Feb 7 14:38:39 GMT 2006

On Sun, Feb 05, 2006 at 09:14:22PM -0800, Charles Gordon wrote:
> I've been working on a very simple Mason-based web front-end to a set of
> database tables. I've been using Class::DBI::Sweet to handle all the
> database interaction, and so far it has been great. I noticed early on that
> lists of objects from the database took N+1 queries to fetch (one query to
> get the list, and then N queries to "flesh" the foreign keys). I switched to
> using the "prefetch" attribute available via Sweet, and now its down to one
> query for the list, which is great.
> However, the "prefetch" attribute only handles "inner" joins, and there are
> a number of cases in which I need a "left" join. These cases generally
> involve optional relationships. Here is a boiled down example:
> Has anyone found a better way to introduce LEFT JOIN's into prefetched-style
> queries with CDBI?

I'm afraid around the time I started looking at this was the point at which
I got tired of fighting the CDBI internals all the time and started DBIx::Class
instead. The Sweet join code is an almighty hack and while it's probably
possible to extend it to do this I doubt it would be much fun :)

     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 ClassDBI mailing list