如何在没有foreignKey时关联HABTM关系?

时间:2014-07-19 21:57:24

标签: cakephp cakephp-2.0 cakephp-2.1 cakephp-2.3

鉴于以下内容: 内容模型

public $hasAndBelongsToMany = array(
    'Tag' => array(
        'className' => 'Tag',
        'joinTable' => 'contents_tags',
        'foreignKey' => 'content_id',
        'associationForeignKey' => 'tag_id',
        'unique' => 'keepExisting',
    )
);

标记模型

public $hasAndBelongsToMany = array(
    'Content' => array(
        'className' => 'Content',
        'joinTable' => 'contents_tags',
        'foreignKey' => 'tag_id',
        'associationForeignKey' => 'content_id',
        'unique' => 'keepExisting',
    )
);

预订模型

public $belongsTo = array(
    'Content' => array(
        'className' => 'Content',
        'foreignKey' => 'content_id',
    ),
);

Book模型有content_id。我怎样(如果可能的话)将图书模型与标签模型联系起来?

0 个答案:

没有答案