0
我沒有獲取某個特定項目的類別。 模型與關係cakephp - 獲取特定類別的項目
- 1項目有許多ProjectCategory(中間表是NodeAssociation)
我使用的hasAndBelongsToMany關係
/示範項目/
public $hasAndBelongsToMany = array( 'ProjectCategory' => array( 'className' => 'ProjectCategory', 'joinTable' => 'NodeAssociation', 'foreignKey' => 'skin_node_id', 'associationForeignKey' => 'source_node_id' ) );
/SQL/
SELECT pc.id,pc.cname AS類
FROM項目p
JOIN nodeassociation NA
ON p.id = na.source_node_id和p.id = 10001
JOIN projectcategory pc
ON na.sink_node_id = pc.id AND sink_node_entity ='ProjectCategory';
FUNCTION in ProjectsController
$joins = array(
array('table' => 'nodeassociation',
'alias' => 'NodeAssociation',
'conditions' => array(
'Project.id = NodeAssociation.source_node_id',
)
),
array('table' => 'projectcategory',
'alias' => 'ProjectCategory',
'conditions' => array(
'NodeAssociation.sink_node_id = ProjectCategory.id', "NodeAssociation.sink_node_entity='ProjectCategory'"
)
)
);
$categories = $this->Project->ProjectCategory->find('all', array('joins' => $joins,
'fields' => array('ProjectCategory.id, ProjectCategory.cname'),
'recursive' => -1,
'conditions' => array('Project.id' => 10001)));
的錯誤,在我看來是
Error: SQLSTATE[42P01]: Undefined table: 7 ERRO: faltando entrada para tabela "Project" na cláusula FROM LINE 1: ...ublic"."nodeassociation" AS "NodeAssociation" ON ("Project"....^
我究竟做錯了什麼?
問候
如果你想跟着蛋糕約定,你的表名應當強調複數。我無法讀取該錯誤,但看起來無法找到「項目」表? – Dave
我無法更改數據庫。 :/是的,它不能找到項目表。 – Jcbo
是否有項目表? – Dave