Issue with doctrine gedmo loggable extension amd stof doctrine extension

config/doctrine/Tag.orm.xml

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
               https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"
    xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
>
<entity name="App\Entity\Tag" table="tag">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO"/>
    </id>
    <field name="tag" type="string" length="50" unique="true" />
    <field name="text" type="string" length="2000" nullable="true">
        <gedmo:versioned/>
    </field>
    <gedmo:loggable log-entry-class="App\Entity\LogEntry"/>
</entity>

config/packages/stof_doctrineextensions.yaml

  stof_doctrine_extensions:
      default_locale: en_US
      orm:
          default:
              loggable: true

This works (Updating)

    $tag = $em->getRepository(Tag::class)->findOneBy(['tag'=>'test']);
    $tag->setTag('test update');
    $tag->setText('test text');
    $em->flush();

This doesn't (Persisting)

    $tag = new Tag();
    $tag->setTag('test');
    $tag->setText('test text');
    $em->persist($tag);
    $em->flush();

    **Throws below exception**

    An exception occurred while executing 'INSERT INTO log_entry (action, logged_at, object_id, 
    object_class, version, data, username, comment, created_by_id, updated_by_id) VALUES (?, ?, ?, 
    ?, ?, ?, ?, ?, ?, ?)' with params ["create", "2018-10-01 17:22:28", null, "App\\Entity\\Tag", 1, "a:1:
    {s:4:\"text\";N;}", null, null, null, null]:

    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'object_id' cannot be null

Its obvious loggable listener is not able to access the new object id or is trying to persist log entry before persisting the original object. I tried debugging seems like LoggableListener's postPersist method is never called while persisting, But works while updating.

0

There are 0 answers