【发布时间】:2014-04-22 20:55:06
【问题描述】:
嗨,我的代码有问题,我想生成一个用户列表,但这有一个组,只需要一组用户。 错误说:
错误:SQLSTATE[42P01]:未定义表:7 错误:缺少表“Grupo”的 FROM 子句条目
这是我的代码:
public function add()
{
$this->loadModel('SoyaProveedor');
$this->loadModel('Soya');
$this->set('oleaginosas', $this->Soya->find('list', array(
'fields'=> array('id','username'),
'conditions' => array('Grupo.categoria' => 'Soya' , 'Grupo.subcategoria' => 'Productor de Oleaginosas')
)));
if ($this->request->is('post')) {
$this->request->data['SoyaProveedor']['nombre'] = strtoupper($this->request->data['SoyaProveedor']['nombre']);
$this->request->data['SoyaProveedor']['codigo'] = strtoupper($this->request->data['SoyaProveedor']['codigo']);
if ($this->SoyaProveedor->save($this->request->data)) {
$this->Session->setFlash(__('La Información fue Guardada.'));
return $this->redirect(array('action' => 'index'));
}
}
}
蛋糕的sql查询生成它:
SQL 查询:SELECT "Soya"."id" AS "Soya__id", "Soya"."username" AS "Soya__username" FROM "public"."users" AS "Soya" WHERE "Grupo"."categoria" = 'Soya' AND "Grupo"."subcategoria" = '生产者 de Oleaginosas'
【问题讨论】:
-
您的问题是您的条件在 Grupo 表上,而您在 Soya 上找到。
-
Soya和Grupo是什么关系?
-
Soya 是用户,用户有组
-
请不要通过编辑来回答问题 - 写下答案并(在允许的情况下)接受它。也就是说 - 您找到了一个非常冗长/困难/不正常的解决方案(并且您再次加入用户表?)。
标签: postgresql cakephp