Closed
Description
First of all, sorry if this has already been reported, but I already checked for 3 days a solution without succeeding.
Here is my situation:
I implement a parent class, GenericMessage
* Message
*
* @ORM\Table(name="message")
* @ORM\Entity(repositoryClass="AppBundle\Repository\MessageRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="message_type", type="string")
* @ORM\DiscriminatorMap({
* "gallery" = "GalleryMessage",
* "text" = "TextMessage",
* })
*/
abstract class GenericMessage {
...
with (at least) two children:
/**
* GalleryMessage
*
* @ORM\Table(name="message_gallery")
* @ORM\Entity()
*/
class GalleryMessage extends GenericMessage
{
and
/**
* TextMessage
*
* @ORM\Table(name="message_text")
* @ORM\Entity()
*/
class TextMessage extends GenericMessage
{
Then I insert create different instances of these two messages:
$t1 = new TextMessage();
$g1 = new GalleryMessage();
$t2 = new TextMessage();
$em->persist($t1);
$em->persist($g1);
$em->persist($t2);
$em->flush();
However, the id are not in the right order, as inserts are nested by entity by the UnitOfWork, if I understood the code well.
Therefore, if we sort by id, we would get $t1
, $t2
, $g1
instead of $t1
, $g1
, $t2
.
Inserts order are:
- GenericMessage --> get id (for instance 4)
- TextMessage -> insert with id 4
- GenericMessage --> get id (for instance 5)
- TextMessage -> insert with id 5
- GenericMessage --> get id (for instance 6)
- GalleryMessage -> insert with id 6
Is there any way to make all the insertions in the right order? For instance insert all the GenericMessage rows, then collect the ids, and the the order doesn't matter?
For instance:
- GenericMessage --> get id (for instance 4)
- GenericMessage --> get id (for instance 5)
- GenericMessage --> get id (for instance 6)
- TextMessage -> insert with id 4
- TextMessage -> insert with id 6
- GalleryMessage -> insert with id 5