mysql-error-1111

CakePHP: How do I count the number of hasMany records in a find?

I have two models, Post hasMany Comment . How do I select all Post that have less than two Comment ? I tried using a find with 'fields'=>array('COUNT(Comment.id) as numComments','Post.*') , (and then doing a numComments < 2 in 'conditions' ). But, I get a Unknown column 'Comment.id' in 'field list'...

MySQL INSERT INTO / ON DUPLICATE KEY with SELECT statement issue

Howdy - I'm a MySQL Noob. I have a table of various business listings and I am trying to populate a second table called cities that contains unique city names along with a count of how many listings per city. I'm able to do a SELECT statement that gets me this data fine like so: SELECT city,state...

ActiveRecord syntax for finding all items with an average rating of x or greater when using a join

I have two models in my rails application. Items and Reviews. Reviews belong to Item and Items has many Reviews. The review model looks like this: create_table "reviews", :force => true do |t| t.text "comment" t.integer "rating" t.integer "reviewable_id" t.string "reviewable_type" t.datetime...