I have ZipCode hasMany Post and am trying to construct a find within
the ZipCode model that will show me all of the ZipCodes that have a
linked Post. The SQL query I'm eventually trying to duplicate is:

SELECT zip_codes.city, states.state, COUNT( * ) AS city_count
FROM zip_codes, states, posts
WHERE posts.zip_code_id = zip_codes.id
AND zip_codes.state_id = states.id
GROUP BY zip_codes.city, states.state
ORDER BY city_count DESC
LIMIT 4 ;

But I'm willing to start small, and for now would love to get this
query

SELECT    zip_codes.city, states.state
FROM      zip_codes, states, posts
WHERE     posts.zip_code_id = zip_codes.id
AND       zip_codes.state_id = states.id;

The ZipCode model has $hasMany = array( 'Post' ). If I place the first
WHERE clause in the conditions, I get an error, and I can't seem to
figure out the joins syntax for the find method.

Thanks,
Chuck

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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