计数记录查询Cakephp

时间:2014-08-03 15:23:11

标签: cakephp

我有三个表Users,Cittas和CittaUsers 每个用户可以拥有多个Citta ...例如,用户1可以拥有CittaUsers 3记录,user_id = 1,citta_id = 3 citta_id = 78 citta_id = 25

我现在想要计算有多少用户将citta_id = 78纳入CittaUsers ..那么CittaUsers中有多少记录是citta_id = 78

我想在UsersController中这样做...所以我创建了一个Model CittaUser:

class CittaUser extends AppModel {
   // public $actsAs = array('Containable');
    public $name = 'CittaUser';
    public $useTable = 'citta_users';
    public $belongsTo = array(
        'cittauser' => array(
            'className'    => 'citta_user',
            'foreignKey'   => 'citta_id'
        )
    );

我将模型加载到UsersController:$ this-> loadModel('CittaUser');

我插入此代码:

$countcitta=$this->CittaUser->find('count',array(
    'conditions'=>array('cittauser.citta_id'=>78));

但我收到错误500.

怎么了?

亚历

0 个答案:

没有答案