我想在索引视图中显示所有拥有照片和城市的用户。 名字和照片都可以。 问题是这个城市。 我创建了模型用户:
public $hasOne = array(
'Photo' => array(
'className' => 'Photo',
'dependent' => true
),
'Scheda' => array(
'className' => 'Scheda',
'dependent' => true
)
);
模特城市
class Citta extends AppModel {
public $hasOne = 'Citta';
}
最后是UsersController
public function index() {
$data= $this->User->find('all', array(
'contain' => array('Photo'),
'conditions'=>array('User.attivo' => '1'),
'group'=>array('User.id'),
'type'=>'INNER'));
$this->loadModel('Citta');
$citta=$this->Citta->find('all', array(
'conditions' => array('Scheda.citta_id = Citta.id'),
));
$this->set('user',$data);
$this->set('citta',$citta);
}
我收到此错误
错误:SQLSTATE [42000]:语法错误或访问冲突:1066不唯一的表/别名:'Citta'
SQL查询:SELECT Citta
。id
,Citta
。value
FROM massaggi2
。cittas
AS Citta
LEFT JOIN massaggi2
。cittas
AS Citta
ON(Citta
。citta_id
= Citta
。id
)WHERE Scheda
。 citta_id
= Citta
。id
怎么了?
由于 亚历
答案 0 :(得分:1)
你的问题是Citta有一个Citta - 两者的名字相同。只需更改Citta拥有的关联名称,例如:
class Citta extends AppModel {
public $hasOne = array(
'OtherCity' => array(
'className' => 'Citta',
'dependent' => false,
);
);
}