Suppose we are submitting a form and changing the year of the second book to 1957.
// submit author object with 1-to-many books:
$_POST = [
'id' => 1,
'name' => 'Jack Kerouac',
'books' => [
[
'id' => 1,
'title' => 'The Town and the City',
'year' => 1950
],
[
'id' => 2,
'title' => 'On the Road',
'year' => 1957 // this value is different than what is in the db
]
]
];
use \My\Model\author;
// this does not work as expected
// (the value is not updated in the db, however inserting a new book does work)
$author = author::get($_POST)->save();
// until this is fixed, there is a work-around
// save the books first, then save the author
$author = author::get($_POST);
foreach ($author->books as $book) {
$book->save();
}
$author->save();
Suppose we are submitting a form and changing the
year
of the second book to1957
.