Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2586

BasicEntityPersister::_insertSql have old cached value, even if classmetadata changes

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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 `myentity_1` 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

        Activity

        Hide
        Fabio B. Silva added a comment -

        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

        Show
        Fabio B. Silva added a comment - 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

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Umed
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: