Given the following tables:
Book
book_id
title
...
Book_User (existence of record indicates that user has read book)
book_id
user_id
For a given user, I want to retrieve a list of *all* books, and flag the
one's he/she has read. The SQL for this is pretty clear:
SELECT book.*, book_user.*
FROM book
LEFT OUTER JOIN book_user
ON ( book_user.book_id = book.book_id
AND book.user_id = 'givenuser'
)
And I can display a flag whenever book_user.user_id is not null. But I
can't seem to figure out a clean way of doing this in DBIC. The join
criteria is dynamic, so it can't be hard-coded into the result source.
So far my solution has been to do two separate queries, selecting
everything from Book, and selecting from Book_User for the given user. I
build a quick little hash from the book_user results and just check the
hash as I loop over the books. It certainly works, but I'm wondering if
anybody's figured out a way to do this type of query more directly in DBIC.
_______________________________________________
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]