Discussion:
Cakephp 3 - save extra data on association table
grb
2014-12-08 11:24:46 UTC
Permalink
Trying to set up an example on how to use join table with extra data I have
the following set:

- table students: id, name, [...]
- table courses: id, title, [...]
- join table courses_students: id, course_id, student_id, grade,
hours_attended

I want to save a student record together with his courses associations on a courses_students table.
Saving entity using the below array works fine for the basic association. It saves both the base class student record as well as the records on the association table.
Array ( [name] => Mark
[courses] => Array (
[_ids] => Array (
[0] => 1
[1] => 2
) ) )
However if I want to save the extra fields on the association table how am I supposed to add these data on the array?

I don't want to save or update the courses associated data, only the association table's data.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+***@googlegroups.com.
To post to this group, send email to cake-***@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
José Lorenzo
2014-12-08 22:11:22 UTC
Permalink
Check the documentation
here http://book.cakephp.org/3.0/en/orm/table-objects.html#saving-additional-data-to-the-joint-table
Post by grb
Trying to set up an example on how to use join table with extra data I
- table students: id, name, [...]
- table courses: id, title, [...]
- join table courses_students: id, course_id, student_id, grade,
hours_attended
I want to save a student record together with his courses associations on a courses_students table.
Saving entity using the below array works fine for the basic association. It saves both the base class student record as well as the records on the association table.
Array ( [name] => Mark
[courses] => Array (
[_ids] => Array (
[0] => 1
[1] => 2
) ) )
However if I want to save the extra fields on the association table how am I supposed to add these data on the array?
I don't want to save or update the courses associated data, only the association table's data.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+***@googlegroups.com.
To post to this group, send email to cake-***@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Loading...