# |
Mar 12th 2018, 07:19 |
aneh |
but get same result |
# |
Mar 12th 2018, 07:19 |
aneh |
$data = [ 'user_id' => 1, 'company_id' => 9, 'addresses' => [ [ 'user_id' => 1, 'company_id' => 9, 'name' => 'Aneh' ] ] ]; |
# |
Mar 12th 2018, 07:19 |
aneh |
i also try with this data |
# |
Mar 12th 2018, 07:18 |
joddit |
It should have addresses plural and have an index key |
# |
Mar 12th 2018, 07:18 |
joddit |
Right so you need to change your data array |
# |
Mar 12th 2018, 07:18 |
aneh |
$this->hasMany('Addresses', [ 'foreignKey' => 'address_header_id' ]); |
# |
Mar 12th 2018, 07:18 |
aneh |
yes |
# |
Mar 12th 2018, 07:16 |
joddit |
Right but you've defined the association as address_headers hasMany addresses right? |
# |
Mar 12th 2018, 07:14 |
aneh |
My address entity table protected $_accessible = [ 'user_id' => true, 'company_id' => true, 'address_header_id' => true, 'name' => true, ]; and address_header table entity protected $_accessible = [ 'id' => true, 'user_id' => true, 'company_id' => true, 'created_date' => true, ]; |
# |
Mar 12th 2018, 07:11 |
joddit |
Can check the FormHpage for how to structure associated data https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-inputs-for-associated-data |
# |
Mar 12th 2018, 07:11 |
joddit |
Something like this https://gist.github.com/anonymous/3201973ab3ab52023829d66bd2d5ee2b |
# |
Mar 12th 2018, 07:09 |
joddit |
of addresses, not a single address |
# |
Mar 12th 2018, 07:09 |
joddit |
your 'addresses key should be an indexed array |
# |
Mar 12th 2018, 07:06 |
joddit |
Maybe your 'address' key needs to be 'addresses'[0] |
# |
Mar 12th 2018, 07:06 |
joddit |
Since it's not a hasOne |
# |
Mar 12th 2018, 07:06 |
joddit |
Try formatting your data differently |
# |
Mar 12th 2018, 07:04 |
joddit |
My guess is, it is ignoring your address data |
# |
Mar 12th 2018, 07:04 |
joddit |
See if the fields are even being caught and marked dirty |
# |
Mar 12th 2018, 07:04 |
joddit |
Check your entity |
# |
Mar 12th 2018, 07:04 |
joddit |
Hrmm |
# |
Mar 12th 2018, 07:04 |
aneh |
i get same result even if i set atomic=> false |
# |
Mar 12th 2018, 07:04 |
joddit |
Well your association code look proper, the data that you're attempting to save looks proper and the controller code looks proper to be honest. |
# |
Mar 12th 2018, 07:00 |
aneh |
Cake is not save data in address table |
# |
Mar 12th 2018, 06:59 |
aneh |
File uploaded https://cakesf.slack.com/files/U2KMFH4MR/F9MG3K4C8/screen_shot_2018-03-12_at_12.29.20_pm.png / https://slack-files.com/T053DPNCM-F9MG3K4C8-17c5877df5 |
# |
Mar 12th 2018, 06:58 |
joddit |
Or she* |
# |
Mar 12th 2018, 06:58 |
joddit |
Hopefully savant chimes in... He'll know |
# |
Mar 12th 2018, 06:57 |
joddit |
Maybe you have to 'atomic' => false since the transaction would stop the ID from being generated, dunno |
# |
Mar 12th 2018, 06:55 |
joddit |
Have you checked if they're being marked dirty? |
# |
Mar 12th 2018, 06:55 |
joddit |
ects using this key by making the custom options the array value. If false no associated records will be saved. (default: true)" |
# |
Mar 12th 2018, 06:55 |
joddit |
Fromt he API docs... "associated: If true it will save 1st level associated entities as they are found in the passed $entity whenever the property defined for the association is marked as dirty. If an array, it will be interpreted as the list of associations to be saved. It is possible to provide different options for saving on associated table obj |
# |
Mar 12th 2018, 06:53 |
joddit |
I usually just save the initial parent record, then user $entity->id to populate the associations and save them that way |
# |
Mar 12th 2018, 06:52 |
joddit |
Checking the API docs rq |
# |
Mar 12th 2018, 06:52 |
joddit |
Examples in the book in the docs only show saving associations on existing records, not creating both initial record and associations at same time |
# |
Mar 12th 2018, 06:50 |
aneh |
wait will post sql here |
# |
Mar 12th 2018, 06:49 |
joddit |
Did it even attempt the insert for the address record(s)? |
# |
Mar 12th 2018, 06:49 |
joddit |
Did you check the SQL log in debugkit? |
# |
Mar 12th 2018, 06:48 |
aneh |
you can check here |
# |
Mar 12th 2018, 06:48 |
aneh |
https://stackoverflow.com/questions/49229158/error-saving-associated-data-cakephp-3 |
# |
Mar 12th 2018, 06:48 |
aneh |
i did not get any error from cakephp but it did not create entry on address table |
# |
Mar 12th 2018, 06:46 |
joddit |
Are you updating an existing record or creating a new record? |
# |
Mar 12th 2018, 06:45 |
joddit |
Please |