Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
will123195 opened this issue May 18, 2014 · 0 comments
Open

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

will123195 opened this issue May 18, 2014 · 0 comments

Comments

@will123195
Copy link
Contributor

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant