I’m trying to use saveAll correctly to update User records for multiple relational models. Below is the array that I’m using to submit to saveAll function:
Array
(
[InterestsubsUser] => Array
(
[0] => Array
(
[interestsub_id] => 3
[user_id] => 1
)
[1] => Array
(
[interestsub_id] => 4
[user_id] => 1
)
[2] => Array
(
[interestsub_id] => 5
[user_id] => 1
)
)
[User] => Array
(
[relationship_status_id] => 1
[ethnicity_id] => 7
[age] => 27
[height_id] => 1
[weight_id] => 1
[image] => testing
)
[LookingforsUser] => Array
(
[0] => Array
(
[lookingfor_id] => 2
[user_id] => 1
)
[1] => Array
(
[lookingfor_id] => 3
[user_id] => 1
)
[2] => Array
(
[lookingfor_id] => 4
[user_id] => 1
)
[3] => Array
(
[lookingfor_id] => 5
[user_id] => 1
)
)
[SocialLinksUser] => Array
(
[0] => Array
(
[social_link_id] => 1
[user_id] => 1
)
[1] => Array
(
[social_link_id] => 2
[user_id] => 1
)
[2] => Array
(
[social_link_id] => 3
[user_id] => 1
)
)
)
SaveAll function is returning true which is good however I cannot see any updated values/rows in relational database tables with HABTM relationship with User table. Also it’s inserting new row of user but I would like to update the user. I have tried $this->User->id = 1 but it’s not working…
Is there a good way around this issue?
Did you try reading value from user table using
$this->User->id = 1?.So that you can say that its not the problem with that code using$this->readTry adding a hidden id field in your form after you can read data from user table..After that try saveall again if you can not update data again.Then try
If save all is not working then i used folwowing function in my cakePHP project>try this in your controller.change acoording to
field you have.
And in your updating action you can call following
OR YOU CAN USE FOLLOWING METHOD TO SAVE ONLY TO USER TABLE AFTER SAVING DATA TO [InterestsubsUser].
In my opinion problem with you is your User table raw is not selecting.