cakephp关系表模型设置

时间:2014-01-05 14:45:16

标签: cakephp cakephp-model

我需要一些帮助,我有3个表,它们是:model,model_profile,profile

我现在拥有的是:

将模型链接到model_profile

public $hasMany = array(
        'Perfil' => array(
            'className' => 'Modelo_perfile',
            'foreignKey' => 'modelo_id',
        ),
        'Fotos' => array(
            'className' => 'Modelo_foto',
            'foreignKey' => 'modelo_id',
        ),
    );

但我需要将model_perfile链接到perfile所以当我调用$ this-> Model-> find('all')时,我会得到模型配置文件名称。

Modelo_perfile表只是ids

id | model_id | profile_id

有没有办法在cakephp模型上链接这个?​​??

谁能帮忙?感谢。

1 个答案:

答案 0 :(得分:0)

好的,感谢 kicaj 我找到了解决方案

我不得不使用haamanyandbelongstomany关系

结果如下:

public $hasAndBelongsToMany = array(
        'Perfile' => array(
            'className' => 'Perfile',
            'joinTable' => 'modelo_perfiles',
            'foreignKey' => 'modelo_id',
            'associationForeignKey' => 'perfil_id',
            'unique' => true,
        )
    );

谢谢大家:)