代码:
$criteria = new CDbCriteria;
$criteria->select='id, name, count(events.id) AS event_relational';
$criteria->with=array('events');
$model = Profiles::model()->findAll($criteria);
回复:
[{"id":"1","name":"Profile 1","event_relational":"0"}]
代码 2:
$criteria = new CDbCriteria;
$criteria->select='id, name';
$criteria->with=array('events');
$model = Profiles::model()->findAll($criteria);
回应 2:
[{"id":"1","name":"Profile 1","event_relational":null},{"id":"2","name":"Profile 2","event_relational":null}...]
当我使用 COUNT 时,查询在第一个 MySQL 条目中停止。我想代码返回所有条目并检查是否有关系事件。
我想要的回应:
[{"id":"1","name":"Profile 1","event_relational":"0"},{"id":"2","name":"Profile 2","event_relational":"1"}...]