I should have searched less API/manual/Google, and more in this
group :x.

The solution has been posted several times here - with the way I've
fixed it having been posted by Tijs Teulings here:
http://groups.google.com/group/cake-php/browse_thread/thread/f23b1825050ad543/014092749592de70?rnum=3#014092749592de70

Sorry to anybody exasperated by people asking this question :).

The code that works for my situation:

$listings = $this->Listing->query(
"
SELECT Listing.* FROM
        listings AS Listing
        LEFT JOIN listings_locations AS ll ON Listing.id = ll.listing_id
        LEFT JOIN locations AS Location ON Location.id = ll.location_id
        LEFT JOIN categories_listings AS cl ON Listing.id = cl.listing_id
        LEFT JOIN categories AS Category ON Category.id = cl.category_id
        WHERE Location.id = '{$chosen_location_id}'
        AND Category.id = '{$chosen_category_id}';
"
);

Perhaps a mention in the HABTM section of the manual here would help:
http://manual.cakephp.org/chapter/models

In the 'Defining and Querying with hasAndBelongsToMany' section,
something like:

If we want to select all Posts and their Tags, the findAll() method
will serve us well. If we want all Posts, but only if they have a
specific tag, then a custom SQL query will do what we want ($this-
>Post->findAll('Tag.id = X') won't). Consider using something such as:

$this->Post->query("
SELECT Post.* FROM posts AS Post
        LEFT JOIN posts_tags AS pt ON Post.id = pt.post_id
        LEFT JOIN tags AS Tag ON Tag.id = pt.tag_id
        WHERE Tag.id = {$chosen_tag_id};
");


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to