Users (UID [PK])
Goods (GID [PK])
Ratings (UID, GID, Rate)
I'd like to exec this SQL but as ActiveRecord, to get most rated goods with related info:
SELECT *, SUM(Rate) AS Rating FROM Ratings AS r, Users AS u, Goods AS g WHERE r.GID=g.GID AND u.UID=g.UID GROUP BY r.GID ORDER BY Rating DESC LIMIT 10
I'm trying to write CDbCriteria:
$criteria = new CDbCriteria(); $criteria->limit = $limit; $criteria->order = "Rating DESC"; $criteria->select = array('*', 'SUM(Rate) AS rating'); $criteria->group = "rating.GID"; $mostRelated = Goods::model()->with("rating", "users")->together()->findAll($criteria);
But I get error: '*' is wrong column
What's wrong?