Skip to content

Loading…

DDC-2586: BasicEntityPersister::_insertSql have old cached value, even if classmetadata changes #3315

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user umed:

BasicEntityPersister caches *insertSql into the *insertSql property field. Its probably good, however I have a problem with it.

My class metadata can changed dynamically, and for example, if entity table has been changed, _insertSql value does not change.

For example, lets say I have such situation:

$entity = new MyEntity('somevalue');
$metadata = $entityManager->getClassMetadata('MyEntity');
$metadata->setPrimaryTable(array('name' => 'myentity_1'));
$entityManager->persist($entity); // here insertSql is already cached with `myentity1` table name
$entityManager->flush();

$entity = new MyEntity('somevalue2');
$metadata = $entityManager->getClassMetadata('MyEntity');
$metadata->setPrimaryTable(array('name' => 'myentity_2'));
$entityManager->persist($entity); // here _insertSql DOES NOT CHANGE, even if class metadata has been changed, because its already cached and does not listens to the class metadata changes
$entityManager->flush();

// and the result I have 2 rows in the same myentity_1 table, but I want to have it in the different tables.

There is no method to clear **insertSql value, and no method to make it know about class metadata changes.
I want to see official solution for this problem

@doctrinebot

Comment created by @FabioBatSilva:

You CANNOT change metadata on the fly.

If you really need to change metadata you can use implement a subscriber/listener listening to loadClassMetadata events..

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.