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

[PreUpdateEventArgs] Allows to add a new value on the entity changeset #600

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/Doctrine/ORM/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ public function setNewValue($field, $value)
$this->entityChangeSet[$field][1] = $value;
}

/**
* Adds a new field value in the entity changeset.
*
* If the field already exists, it sets the new value.
*
* @param string $field
* @param mixed $value
*
* @return void
*/
public function addNewValue($field, $value)
{
$metadata = $this->getEntityManager()->getClassMetadata(get_class($this->getEntity()));

if ( ! $metadata->hasField($field)) {
$this->assertValidField($field);
}

$this->entityChangeSet[$field][1] = $value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not create a valid changeset as you don't set the old value.

Btw, you can set the value in your entity and use $event->getEntityManager()->getUnitOfWork()->recomputeSingleEntityChangeSet($event->getEntity())

}

/**
* Asserts the field exists in changeset.
*
Expand Down