From 18c15cb5f59ede446ead94a623a987e1c27b7280 Mon Sep 17 00:00:00 2001 From: celsowm Date: Tue, 25 Jul 2023 14:48:22 -0300 Subject: [PATCH] Update saving-data.rst saving many-to-many additional example --- en/orm/saving-data.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/en/orm/saving-data.rst b/en/orm/saving-data.rst index 55ab8c5def..6b385264b9 100644 --- a/en/orm/saving-data.rst +++ b/en/orm/saving-data.rst @@ -1035,6 +1035,18 @@ by setting data to the ``_joinData`` property:: $studentsTable->save($student); +The example above will only work if the property ``_joinData`` is already a +reference to a Join Table Entity. If this is not your case you can populate +using the Table to create the entity:: + + $coursesMembershipsTable = $this->getTableLocator()->get('CoursesMemberships'); + $student->courses[0]->_joinData = $coursesMembershipsTable->newEntity([ + 'grade' => 80.12, + 'days_attended' => 30 + ]); + + $studentsTable->save($student); + The ``_joinData`` property can be either an entity, or an array of data if you are saving entities built from request data. When saving junction table data from request data your POST data should look like::