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

Cascade clone for OneHasMany relationship #260

Open
SiViN opened this issue Nov 2, 2017 · 1 comment
Open

Cascade clone for OneHasMany relationship #260

SiViN opened this issue Nov 2, 2017 · 1 comment

Comments

@SiViN
Copy link

SiViN commented Nov 2, 2017

check pls this test...

public function testCloningOneHasManyAuthor()
{
    /** @var Author $author */
    $author = $this->orm->authors->getById(1);

    $booksCount = $author->books->count();
    Assert::same($booksCount, $author->books->count()); //OK

    $newAuthor = clone $author;

    Assert::same($author->name, $newAuthor->name);
    Assert::same($booksCount, $newAuthor->books->count()); //OK
    Assert::same($booksCount, $author->books->count()); //FAIL

    Assert::false($author->isPersisted());
    Assert::true($author->isModified());

    $this->orm->authors->persistAndFlush($newAuthor);

    Assert::true($newAuthor->isPersisted());
    Assert::false($newAuthor->isModified());
    Assert::same($booksCount, $newAuthor->books->countStored());
    Assert::same($booksCount, $author->books->countStored());
}

Here is code + sql command

$author = $this->model->authors->getById(1);
$newAuthor = clone $author;
$this->model->authors->persistAndFlush($newAuthor);

    ::TRANSACTION BEGIN:: 	
    INSERT INTO `authors` (`name`, `born`, `web`, `favorite_author_id`) VALUES ('Writer 1', NULL,         'http://example.com/1', NULL) 	
    UPDATE `books` SET `author_id` = 4 WHERE `id` = 2 	
    UPDATE `books` SET `author_id` = 4, `translator_id` = 4 WHERE `id` = 1 	
    ::TRANSACTION COMMIT::

New author stole books old author..

@hrach hrach added the bug label Nov 2, 2017
@hrach hrach added this to the v3.0 milestone Nov 2, 2017
@hrach
Copy link
Member

hrach commented Nov 11, 2017

Ok, I have taken a closer look and this seems to be the wanted behavior and not a bug. By default it does not make sence to duplicate all relationship, this would end with duplicatingn the whole entity tree.

Though, I can image a support by setting a cascade property similarly as for persist/remove. So I'm marking this a feature request.

@hrach hrach removed this from the v3.0 milestone Nov 11, 2017
@hrach hrach added feature and removed bug labels Nov 11, 2017
@hrach hrach changed the title Wrong clone OneHasMany Cascade clone for OneHasMany relationship Nov 11, 2017
@hrach hrach removed the feature label Oct 1, 2024
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

Successfully merging a pull request may close this issue.

2 participants