Log message #4209690

# At Username Text
# Oct 19th, 15:00 kailas @ndm sorry for stepping away. creating a new shipment
# Oct 19th, 14:32 slackebot1 https://book.cakephp.org/3.0/en/orm/saving-data.html#patching-hasmany-and-belongstomany
# Oct 19th, 14:32 ndm Generally if you want to associate existing records, you'd pass the primary key property of that existing record, not the foreign key in the join table, ie `shipment_handling_units[0].order_lines[$i].id` instead of `shipment_handling_units[0].order_lines[$i]._joinData.order_line_id` And if you'd wanted to update a record, you'd usually patch an entity obtained from the database that includes the associated records.
# Oct 19th, 14:21 ndm Are you creating a new shipment, or updating an existing one?
# Oct 19th, 14:19 kailas @ndm ah, yeah, the debugs of the pre-save and the patch arrays was key. part of the problem was the [$i]. should have been .$i. in my form input. now the problem is that it’s trying to create new order lines, rahter than associate with the existing ones
# Oct 19th, 14:13 kailas k
# Oct 19th, 14:13 ndm Well, that might be (part of) your problem. Debug the entity after patching to check what it looks like, and make sure that your `save()` call uses the correct `associated` option too.
# Oct 19th, 14:12 kailas to be clear, i’m patching a newEntity that is empty
# Oct 19th, 14:12 kailas ugh. didn’t work. not sure how to debug this further (since it does save the shipmehandling unit and there are no errors)
# Oct 19th, 14:11 kailas @ndm ok, cool, will try it!
# Oct 19th, 14:10 ndm Generally that looks OK I think. Not sure if you actually need to put the foreign key in the form if the entity that you're patching contains all the associated entities.
# Oct 19th, 14:06 kailas @ndm the form inputs are inside a foreach that’s iterating through all the lines I can add
# Oct 19th, 14:04 kailas @ndm so, to put it all in one place, https://gist.github.com/kailasnarendran/ef0bb5536cb9d13a97e5ac3ad4d82252 . does that look right?
# Oct 19th, 14:01 ndm No, if there is no such association and it's just BTM, then this shouldn't be in the `associated` option (there are edge cases where you want to do something like that), and it should just be `ShipmentHandlingUnits.OrderLines`, in that case your original property path would be correct.
# Oct 19th, 13:59 kailas so ShipmentHandlingUnits belongsTo OrderLinesShipmentHandlingUnits (need to add this), so then I can create those entities that will link ShipmentHandlingUnits to OrderLines (via the BTM relationship)
# Oct 19th, 13:57 kailas Do I need to define that explicitly as well?
# Oct 19th, 13:57 kailas yeah, i don’t have an explicit association between ShipmentHandlingUnits and OrderLinesShipmentHandlingUnits (it’s just implied with the BTM between ShipmentHandlingUnits and OrderLines
# Oct 19th, 13:56 ndm No, I just cut of the rest because the problem is the missing association, assuming that the `associated` option is telling the truth.
# Oct 19th, 13:55 kailas oh, i see, so I don’t actually set the value of _joinData, i need to set those fields in .orderlines_shipment_handling_units[] explicitly? so shipment_handling_units[0].orderlines_shipment_handling_units[0].order_line_id=1, shipment_handling_units[0].orderlines_shipment_handling_units[0].qty=3, etc…
# Oct 19th, 13:53 ndm Your path is only two levels deep, but your association is three levels deep. It should be something like `shipment_handling_units[index].orderlines_shipment_handling_units[index].order_lines[index]...`
# Oct 19th, 13:49 kailas @ndm is that the @this->Shipments->patchEntity ?
# Oct 19th, 13:48 kailas @ndm hrm.. i’m sorry, i don’t understand what you mean by “your path is missing the property”
# Oct 19th, 13:47 ndm No no... sorry, I just need to wake up first, it needs and index too. But your path is missing the property for `OrderLinesShipmentHandlingUnits`.
# Oct 19th, 13:46 kailas @ndm shipment_handling_units[0].order_lines[]._joinData.order_line_id = … ?
# Oct 19th, 13:45 kailas @ndm oh, i see, so i should get rid of the $i?
# Oct 19th, 13:45 ndm *c
# Oct 19th, 13:45 ndm Wait, all keys except x
# Oct 19th, 13:45 kailas @ndm so my patch is : $this->Shipments->patchEntity($shipment, $this->request->getData(),[‘associated’=>[‘ShipmentHandlingUnits.OrderLinesShipmentHandlingUnits.OrderLines’]]); my individual lines are (iterating through the order lines) : <?=$this->Form->input(“shipment_handling_units[0].order_lines[$i]._joinData.order_line_id”,[‘type’=>‘hidden’,‘value’=>$orderLine->id]); ?>
# Oct 19th, 13:43 ndm The path is still wrong, all keys need an index ;) Anyways, by default only first level associations are patched and saved, for deeper associations you need to explicitly allow them using the `associated` option for patching and saving, maybe that's your problem.
# Oct 19th, 13:35 kailas I’m trying to create an entity A and B (and existing C) where : A has many B and B BelongsToMany C. in my patch entity array i include the a.b[0].c._joinData.stuff values. On my save, A and B are created, but the join table entities between B and C are not created (from the _joinData data). is that even possible?
# Oct 19th, 12:54 admad When I am faced with such a situation I usually just keep mum :slightly_smiling_face:
# Oct 19th, 12:39 alexdd55976 I would, but I have no experience with all that :,)
# Oct 19th, 12:33 admad In case anyone wants to weight in on this your thoughts are welcome https://github.com/cakephp/cakephp/pull/13766
# Oct 19th, 12:18 loginews @alex. thanks. something else must be wrong. I will investigate.
# Oct 19th, 11:28 alexdd55976 @loginews no, there is no cache. You can see the entries instantly in the database.
# Oct 19th, 09:54 arif.h how to use form element in cake
# Oct 19th, 09:26 loginews Is there then a cache which I have to flush somewhere ?
# Oct 19th, 09:25 loginews My use of cakephp is more or less limited to crud screens generated by the bake utility.
# Oct 19th, 09:24 loginews I had this situation a couple of times. When I tried to look into the problem, the latter disappeared.
# Oct 19th, 09:23 loginews Part of my application is written in pure php.
# Oct 19th, 09:21 loginews as for me, I used cakephp to input data, but it seems that pure php does not see the entries immediately. Is there a cache in cakephp that I should flush somewhere ?