Model Join With And

Here is my DB structure…


table `users`

PK `id`


table `webservices`

PK `id`


table `users_webservices`

PK `usersid`, `webservicesid`



Here is what I’m trying to accomplish: For User 1, list all webservices and indicate which ones he’s already chosen.


SELECT w.*, IF(uw.usersid IS NULL, 0, 1) isused

FROM webservices w

LEFT JOIN users_webservices uw ON uw.webservicesid = w.id AND usersid = 1

Right now I’m doing it using 2 simpler queries and 2 foreach loops, which drives me nuts. I want to do it the right way, in the model, like this:


Webservices::model()->indicateUserUsage($usersid)->findAll()

But like I mentioned, I don’t see many examples of this type of thing. I tried DB Criteria but it just did nothing. Any help would be much appreciated. :)