Hello, I'd like to use CakePHP convention in querying the following

SELECT
        tags.name AS tag_name,
        COUNT(ads_tags.tag_id) AS tag_count,
        MAX(ads_tags.created) AS tag_date
FROM
        tags INNER JOIN
        ads_tags ON tags.id = ads_tags.tag_id INNER JOIN
        ads ON ads.id = ads_tags.ad_id AND ads.closed = 0 AND ads.suspended =
0 AND ads.hidden = 0
GROUP BY
        tags.name


The model Ad hasAndBelongsTo Tag
Thus ads_tags is the joining table.

Should I stick to using query() instead of find() ?

If I use query(), the result appears as

Array
(
        [0] => Array
        (
                [tags] => Array
                (
                        [tag_name] => 'some tag'
                )
                [0] => Array
                (
                        [tag_count] => 10
                )
                [ads_tags] => Array
                (
                        [tag_date] => '123546678'
                )
        )
        .
        .
        .
)

Right now, I added a UNION to a dummy row to break Cake's auto
formatting, so it became

Array
(
        [0] => Array
        (
                [0] => Array
                (
                        [tag_name] => 'some tag'
                        [tag_count] => 10
                        [tag_date] => '123546678'
                )
        )
        .
        .
        .
)


Please advise on how to make the query more Cake-like? :P

--~--~---------~--~----~------------~-------~--~----~
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