1

我有这样的东西

$model=UserCategory::model()->findAll(array('with'=>array('user.department','totalCount'=>array('condition'=>"user.department.name='Science'"))));

但它说 Unknown column 'user.department.name' 我知道它为什么这么说但是我将如何实现它

我有以下关系

UserCategory
'user' => array(self::HAS_MANY, 'UserCategory', 'categoryId'),
'totalCount' => array(self::STAT, 'UserCategory', 'categoryId'),//counts total of user under each category
User
'userCat' => array(self::BELONGS_TO, 'UserCategory', 'categoryId'),
'department' => array(self::BELONGS_TO, 'Department', 'departmentId'),
Department
'userDept' => array(self::HAS_MANY, 'User', 'departmentId'),

简而言之,我想找到属于科学系的每个类别下的用户总数

4

1 回答 1

0

要查找属于部门科学的每个类别下的用户总数,“totalCount”关系的正确定义可能是这样的:

'totalCount' => array(self::STAT, 'User', 'category' /* *See note below */, 'condition'=>'user.department=Science'),

*我使用“类别”假设它是包含用户表中类别表的外键的属性的名称。当然,您应该将其更改为属性的正确名称。

现在只需 $model->totalCount 将返回您需要的数字。

但我必须说,我不能 100% 确定上述代码语法的正确性,但是一旦你尝试过,通过一些反馈可以很容易地纠正它。

于 2011-12-24T03:38:32.843 回答