1

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
6
  • In User table have you field resume_id or user_id?
    – Sadikhasan
    Commented Jun 23, 2014 at 10:07
  • In my resume table field user_id is exist.
    – Archana
    Commented Jun 23, 2014 at 11:58
  • You display user_id in array structure and in table format you are display resume_id will both same?
    – Sadikhasan
    Commented Jun 23, 2014 at 12:00
  • 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
    Commented Jun 23, 2014 at 16:05
  • 1
    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
    Commented Jun 24, 2014 at 12:03

2 Answers 2

1

try do that:

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.