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

Mapping to existing instance #1

Closed
smoelker opened this Issue Jan 11, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@smoelker
Copy link

smoelker commented Jan 11, 2019

Is there any way to map to an existing instance of the target class? For example:

$entity = $this->em->find(EntityClass::class, $id);
$this->mapper->map($domainObject, $entity);
$this->em->persist($entity);
@joelwurtz

This comment has been minimized.

Copy link
Member

joelwurtz commented Feb 5, 2019

Yes there is, you can use the setObjectToPopulate from context for that

$entity = $this->em->find(EntityClass::class, $id); 
$context = new Context();
$context->setObjectToPopulate($entity);

$this->mapper->map($domainObject, EntityClass::class, $context);
$this->em->persist($entity);

Adding an check to automatically doing that should not be so difficult

@smoelker smoelker closed this Feb 18, 2019

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