【问题标题】:CakePHP Sub QueriesCakePHP 子查询
【发布时间】:2014-07-31 16:41:44
【问题描述】:

我想在索引视图中显示所有用户的照片和城市。 名字和照片都可以。 问题是城市。 我创建了模型用户:

public $hasOne = array(
        'Photo' => array(
            'className' => 'Photo',
            'dependent' => true
        ),
        'Scheda' => array(
            'className' => 'Scheda',
            'dependent' => true
        )
    );

还有模范城市

class Citta extends AppModel {
    public $hasOne = 'Citta';
}

最后是用户控制器

  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 Not unique table/alias: 'Citta'

SQL 查询:SELECT Citta.id, Citta.value FROM massaggi2.cittas AS Citta LEFT JOIN @987654@31@.cittas AS @97654332@ AS @98 987654334@.citta_id = Citta.id) 其中Scheda.citta_id = Citta.id

怎么了?

谢谢 亚历克斯

【问题讨论】:

  • Citta 有一个 Citta?这是预定的亲子关系吗?
  • 我是 cakephp 的新手......可能我错过了一些东西。如何修改 Citta hasOne Citta?我想检索每个用户的城市

标签: cakephp


【解决方案1】:

您的问题是 Citta 有一个 Citta - 两者都命名相同的东西。只需更改 Citta 拥有的关联名称,例如:

class Citta extends AppModel {
     public $hasOne = array(
            'OtherCity' => array(
                 'className' => 'Citta',
                 'dependent' => false,
             );
      );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    相关资源
    最近更新 更多