I have two tables: users and posts. I’m trying to select any users that have at least one post.
I’m guessing this require either a join or a subselect. Is there something in CakePHP that makes this simple?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use counter caching, see http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#belongsto
No additional query needed in this case. It will automatically in- and decrease the count in the users table if you add/delete posts.
Example: