1
votes

I have two tables resumes and links. resumes has hasmany relation with links.I want to save many links for single resume.

My $this->request->data array is like

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;
}

This is working and my data is saved in resumes table properly but in links table data saved like following:

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

I want like

id | resume_id | user_id | link
1  | 1         |         | www.google.com
2
In User table have you field resume_id or user_id? - Sadikhasan
In my resume table field user_id is exist. - Archana
You display user_id in array structure and in table format you are display resume_id will both same? - Sadikhasan
You really need to spice up your question with some details. Are you using the latest 3.x version? What do the generated queries look like? What does debug($resume) say before and after saving (please update your question with debugging results, don't put them here in the comments)? Any validation errors? Do you have any before save logic implemented? Why don't you want the user_id to be saved (as shown in your "I want like" example)? - ndm
Well, besides the fact that questions should be self contained, ie not dependent on external information, crosspostings are pretty impolite as someone somewhere is wasting his/her time on your question. - ndm

2 Answers

1
votes

try do that:

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

if ($this->Resumes->save($resume, ['associated' => ['Links']])) {
    // return true;
}
0
votes

Go to your Model/Entity/Link.php and add link to protected $_accessible array