Skip to content

1-to-many nested objects do not update #307

Description

@will123195

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();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions