1

我有两个表简历和链接。简历与链接有很多关系。我想为单个简历保存许多链接。

我的 $this->request->data 数组就像

Array
(
[alternate_email] => 
[mobile] => 23232
[level] => Student
[youtube] => 
[links] => Array
    (
        [0] => Array
            (
                ['link'] => www.google.com
                ['user_id'] => 1
            )

        [1] => Array
            (
                ['link'] => abc.com
                ['user_id'] => 1
            )

    )

)


$resume = $this->Resumes->newEntity($this->request->data);
if ($this->Resumes->save($resume)) {
// return true;
}

这是有效的,我的数据正确保存在简历表中,但保存在链接表中,如下所示:

id | resume_id | user_id  | link
1  | 1         |          |

我想要喜欢

id | resume_id | user_id | link
1  | 1         |         | www.google.com
4

2 回答 2

1

尝试这样做:

$resume = $this->Resumes->newEntity($this->request->data, ['associated' => ['Links']]);

if ($this->Resumes->save($resume, ['associated' => ['Links']])) {
    // return true;
}
于 2016-04-08T12:21:58.867 回答
0

转到您的Model/Entity/Link.php并添加linkprotected $_accessible数组

于 2018-03-09T00:29:29.373 回答