On Fri, Jul 10, 2009 at 11:39, A Murka<[email protected]> wrote:
> On Fri, Jul 10, 2009 at 9:59 AM, Rob Kinyon<[email protected]> wrote:
>> On Fri, Jul 10, 2009 at 00:08, A Murka<[email protected]> wrote:
>> [snip]
>>> Do I just have to create a method that does both joins at once? Is a
>>> better way to implement these aggergates?
>>
>> There is such a thing as putting too much into one query. These
>> queries do very different things. So, just do two queries. Simplify
>> your life.
>
> The trouble with that is that it would mean making an extra query for
> each image as it's displayed: one to select all the images, then one
> for each to select the user's rating for it. On a thumbnail page with
> many images, this would mean many extra queries.

Two queries. One to get all the images, then one to get all the user
ratings for each image. Use the new subquery interface.

my $rs_all_images = resultset('Image')->get_all_images;
my $rs_user_ratings = resultset('UserRatings')->search({
    user_id => $user->id,
    image_id => [ $rs_all_images->get_column('image_id')->as_query ],
})

Rob

_______________________________________________
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