0

我没有访问特定项目的类别。模型和关系

  • 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 类别

来自项目 p

JOIN 节点关联 na

ON p.id = na.source_node_id 和 p.id=10001

加入项目分类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".... ^

我究竟做错了什么?

此致

4

1 回答 1

0

在您的项目模型中设置它:

public $useTable = 'project';
于 2013-05-16T15:27:19.663 回答