Hi guys,

  I'm trying to implement the following SQL in DBIx::Class and I seem to be 
running into difficulty 
with the "joining to the same table twice" bit:

SELECT  me.*
     ,  image_1.image_name
     ,  image_1.image_location
     ,  image_2.image_name
     ,  image_2.image_location
  FROM  content me
     ,  image   image_1
     ,  image   image_2
 WHERE  me.content_id      = $content_id
   AND  me.content_id        = image_1.content_id
   AND  image_1.content_id = image_2.content_id
   AND  image_1.image_type = 'thumbnail'
   AND  image_2.image_type = 'main'         

I have the table files all setup and non-complex queries are working fine.
Here's the relationships from the table files:

>From Content.pm:

__PACKAGE__->has_many(image => 'DB::Main::Image', 'content_id');

>From Image.pm:

__PACKAGE__->belongs_to(content  => 'DB::Main::Content' , 'content_id');



>From the little "Joining to the same table twice" blurb in the
DBIx::Class::Manual::Joining, it appears that something like the
following should

maybe work:

    my $rs = $schema->resultset('Content')->search(
      { 
      , 'image_1.image_type' => 'thumbnail'
      , 'image_2.image_type' => 'main'
      },
      {
        join      => [qw/ image image /],
        prefetch  => [qw/ image image/]
      },
    );

Of course, I'm totally misunderstanding it and it doesn't.  Anyone have any 
ideas for how to implement such a query?
MANY, MANY THANKS IN ADVANCE!!!

-ed

_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star 
power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to