Hi Christian,

To accomplish this, I already tried the following (has_many relationship
between tables is named 'downloads'):

     $rs>search({}, {
         join =>  'downloads',
         '+select' =>  [ { count =>  'downloads.id' } ],
         '+as' =>  [ 'downloadcount' ],
         group_by =>  'me.id',
     });

Unfortunately, this only produces this (DBIC_TRACE):

     SELECT me.*, COUNT( downloads.id ) FROM publiclinks me
         LEFT JOIN publicdownloads downloads ON downloads.linkid = me.id
         GROUP BY me.id


yesterday i build the same - "+as" only defines that you access "downloadcount" with $object->get_column('downloadcount')

If you like to order by this value, try this, or build the accessor in the Row-Class.

      $rs>search({}, {
          join =>  'downloads',
          '+select' =>  [ 'COUNT(downloads.id) AS downloadcount' ],
          '+as' =>  [ 'downloadcount' ],
          group_by =>  'me.id',
          order_by => 'downloadcount DESC',
      });

<http://search.cpan.org/~ribasushi/DBIx-Class-0.08103/lib/DBIx/Class/ResultSet.pm#+as>

regards,
Jens

_______________________________________________
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