DDC-3772: ORM\PreFlush() not Persisted in Database but return right value in my form #4623

Open
opened 2026-01-22 14:46:11 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 15, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user zagloo:

I have a problem with a Preflush() method.

When I valid my form, my form return to me the values that expected but they are not persisted into the database in the case where I create a new Entity.

to a better understand for you, all files that I'm using are in this Gist :
https://gist.github.com/zagloo/1eaedffc2f479686d98f

I have 2 Entities :

  • «First_» with fields named «field1» and «_field2»
  • «Other_» with fields named «field3» and «_field4»

These 2 Entities have these relation between them :

  • «**First_» have OneToMany_ with «Other»
  • «**Other_» have ManyToOne_ with «First»

Then I my controller TestController, I create a form with «FirstType_» and «_OtherType» and render it in test_preflush,html,twig

Feature of my form : I'm using a custom textarea named «**textarea_test_» thanks to a TestType_ which using a Transformer TestTranformer.

This Transformer allows to transform a *PersistCollection* in a String and conversely with the reverseTransform.

In the Transformer **TestTranformer_, public function transform($value) method concatenate each field3_ from Other Entity in

tag.

Vsual example :

Database for «First» Entity
!https://cloud.githubusercontent.com/assets/8613226/8109975/fece771a-1059-11e5-9660-eb5d10b511ca.png!

Database for «Other» Entity
!https://cloud.githubusercontent.com/assets/8613226/8109983/09b3beb0-105a-11e5-95c9-f7b741e8ed7d.png!

The render in twig of the form with the transformer :
!https://cloud.githubusercontent.com/assets/8613226/8109988/0f6b1f7e-105a-11e5-9df0-ceae54c0bfd3.png!

Until here, no problem, I have what I expected, a textarea with a concatenation of field3 !

Then, if I modify a value, no problem, the *PreFluch()* contained at the end of «First» Entity works.
-> value of *field3* for the first entity Other is changed by "toto" in database and returned right in my twig form !

/****
*@ORM\PreFlush()
*/

public function testPreFlush()
{
    $this->Others->first()->setField3('toto');
}

Database for «Other» Entity
!https://cloud.githubusercontent.com/assets/8613226/8110399/594e9056-105c-11e5-964f-3c73e1121f7f.png!

The render in twig of the form with the transformer :
!https://cloud.githubusercontent.com/assets/8613226/8110397/570743ce-105c-11e5-8906-c693d527bf0b.png!

Now, here is my PROBLEM !
I delete all in my textarea and add a new *

* with an ID and a new value like
NEW VALUE

!https://cloud.githubusercontent.com/assets/8613226/8110833/9e0639f4-105e-11e5-9d75-a64ffb035544.png!

Normally, my *Reversetransformer* create a new Other() and set value into it. (see TestTransformer Gist from the line 55).

But when I valid the form, in return, in my twig I get a good text area with *

toto
* BUT in the Database the Preflush has not been persisted !

My twig (Good return)
!https://cloud.githubusercontent.com/assets/8613226/8110743/46b190e0-105e-11e5-91c1-e594df12b00c.png!

My Database Other Entity
!https://cloud.githubusercontent.com/assets/8613226/8110776/6f523c52-105e-11e5-9463-cf6811ba95b1.png!

TO RESUME,

if I just modify values in text area, no problem
=> toto is persisted in database and return in my form twig.

But if I add a new field3, toto is returned into my twig (good!) but not persisted into the database (not good....!!)...

Where is the problem please ? (and sorry for my english)

For Information , here are the different versions that I'm using thanks to the command composer show -i in the console of my IDE :

For Symfony :
symfony/symfony v2.7.0 The Symfony PHP framework

For Doctrine :
doctrine/annotations v1.2.4 Docblock Annotations Parser
doctrine/cache v1.4.1 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.3.0 Collections Abstraction library
doctrine/common v2.5.0 Common Library for Doctrine projects
doctrine/data-fixtures v1.1.1 Data Fixtures for all Doctrine Object Managers
doctrine/dbal v2.4.4 Database Abstraction Layer
doctrine/doctrine-bundle v1.5.0 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle v1.0.1 Symfony2 Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle dev-master c5ff054 Symfony DoctrineFixturesBundle
doctrine/inflector v1.0.1 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm v2.4.7 Object-Relational-Mapper for PHP

Originally created by @doctrinebot on GitHub (Jun 15, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user zagloo: I have a problem with a Preflush() method. When I valid my form, my form return to me the values that expected but they are not persisted into the database in the case where I create a new Entity. to a better understand for you, all files that I'm using are in this Gist : https://gist.github.com/zagloo/1eaedffc2f479686d98f I have 2 Entities : - «**First_» with fields named «_field1_» and «_field2**» - «**Other_» with fields named «_field3_» and «_field4**» These 2 Entities have these relation between them : - «**First_» have *OneToMany_ with «*Other**» - «**Other_» have *ManyToOne_ with «*First**» Then I my controller TestController, I create a form with «**FirstType_» and «_OtherType*» and render it in *test_preflush,html,twig** Feature of my form : I'm using a custom textarea named «**textarea_test_» thanks to a *TestType_ which using a Transformer *TestTranformer**. This Transformer allows to transform a **PersistCollection\* <ins>in</ins> a _String_ and conversely with the *reverseTransform**. In the Transformer **TestTranformer_, public function transform($value) method concatenate each *field3_ from _Other_ Entity in *<div>** tag. Vsual example : Database for «**First**» Entity !https://cloud.githubusercontent.com/assets/8613226/8109975/fece771a-1059-11e5-9660-eb5d10b511ca.png! Database for «**Other**» Entity !https://cloud.githubusercontent.com/assets/8613226/8109983/09b3beb0-105a-11e5-95c9-f7b741e8ed7d.png! The render in twig of the form with the transformer : !https://cloud.githubusercontent.com/assets/8613226/8109988/0f6b1f7e-105a-11e5-9df0-ceae54c0bfd3.png! Until here, no problem, I have what I expected, a textarea with a concatenation of **field3** ! Then, if I modify a value, no problem, the **PreFluch()\* contained at the end of «*First**» Entity works. -> value of **field3\* for the first entity _Other_ is changed by *"toto"** in database and returned right in my twig form ! ``` xml /**** *@ORM\PreFlush() */ public function testPreFlush() { $this->Others->first()->setField3('toto'); } ``` Database for «**Other**» Entity !https://cloud.githubusercontent.com/assets/8613226/8110399/594e9056-105c-11e5-964f-3c73e1121f7f.png! The render in twig of the form with the transformer : !https://cloud.githubusercontent.com/assets/8613226/8110397/570743ce-105c-11e5-8906-c693d527bf0b.png! Now, here is my PROBLEM ! I delete all in my textarea and add a new **<div>\* with an ID and a new value like *<div id="88">NEW VALUE</div>** !https://cloud.githubusercontent.com/assets/8613226/8110833/9e0639f4-105e-11e5-9d75-a64ffb035544.png! Normally, my **Reversetransformer\* create a _new Other()_ and set value into it. (see *TestTransformer** Gist from the line 55). But when I valid the form, in return, in my twig I get a good text area with **<div id="17">toto</div>\* BUT in the Database the *Preflush** has not been persisted ! My twig (Good return) !https://cloud.githubusercontent.com/assets/8613226/8110743/46b190e0-105e-11e5-91c1-e594df12b00c.png! My Database **Other** Entity !https://cloud.githubusercontent.com/assets/8613226/8110776/6f523c52-105e-11e5-9463-cf6811ba95b1.png! TO RESUME, if I just modify values in text area, no problem => toto is persisted in database and return in my form twig. But if I add a new field3, toto is returned into my twig (good!) but not persisted into the database (not good....!!)... Where is the problem please ? (and sorry for my english) For Information , here are the different versions that I'm using thanks to the command composer show -i in the console of my IDE : For Symfony : symfony/symfony v2.7.0 The Symfony PHP framework For Doctrine : doctrine/annotations v1.2.4 Docblock Annotations Parser doctrine/cache v1.4.1 Caching library offering an object-oriented API for many cache backends doctrine/collections v1.3.0 Collections Abstraction library doctrine/common v2.5.0 Common Library for Doctrine projects doctrine/data-fixtures v1.1.1 Data Fixtures for all Doctrine Object Managers doctrine/dbal v2.4.4 Database Abstraction Layer doctrine/doctrine-bundle v1.5.0 Symfony DoctrineBundle doctrine/doctrine-cache-bundle v1.0.1 Symfony2 Bundle for Doctrine Cache doctrine/doctrine-fixtures-bundle dev-master c5ff054 Symfony DoctrineFixturesBundle doctrine/inflector v1.0.1 Common String Manipulations with regard to casing and singular/plural rules. doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. doctrine/orm v2.4.7 Object-Relational-Mapper for PHP
admin added the Bug label 2026-01-22 14:46:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4623