You are getting it wrong.
We are not talking about the tables for the inheritance.
We are talking about related entities of the inheritence-mapped entities.
So it is like this:
PARENT ---> OneToMany ---> PRODUCT_EROR
|
v
CHILD ---> OneToMany ---> MODULE
The delete-order should be PRODUCT_ERROR --> MODULE --> PARENT (+CHILD)
but it seems to be PRODUCT_ERROR --> PARENT (+CHILD) --> MODULE
Am Freitag, 27. Juni 2014 17:47:42 UTC+2 schrieb hoessi:
>
> the anser is simple: the doctrine doku say something like that:
>
> > When you do not use the SchemaTool to generate the required SQL you
> should know that deleting a class table inheritance makes use of the
> foreign key property ON DELETE CASCADE in all database implementations. A
> failure to implement this yourself will lead to dead rows in the database.
>
> so it is not realy clear why is to set a onDelete cascade by database. the
> code clear this:
>
> JoinedSubclassPersister.php:274
>
> // If the database platform supports FKs, just
> // delete the row from the root table. Cascades do the rest.
> if ($this->platform->supportsForeignKeyConstraints()) {
> $rootClass =
> $this->em->getClassMetadata($this->class->rootEntityName);
> $rootTable = $this->quoteStrategy->getTableName($rootClass,
> $this->platform);
>
> $this->conn->delete($rootTable, $id);
>
> return;
> }
>
> so, just set the "onDelete=CASCADE" on all subTables and all works fine!
>
> greez,
> hoessi!
>
>
> Am Mittwoch, 11. Juni 2014 21:33:39 UTC+2 schrieb Björn Zeutzheim:
>>
>> Hi there I have a problem with doctrine in symfony.
>>
>> I have the following entities:
>>
>> /**
>> * FourTeachersSchuldruckBundle:Product
>> *
>> * @ORM\Entity
>> * @ORM\Table(name="product")
>> * @ORM\InheritanceType("JOINED")
>> * @ORM\DiscriminatorColumn(name="type", type="string")
>> * @ORM\DiscriminatorMap({"heft" = "ModuleProduct"})
>> * @ORM\HasLifecycleCallbacks
>> */
>> abstract class Product {
>> // ....
>> }
>>
>> /**
>> * @ORM\Entity
>> * @ORM\Table(name="product_module")
>> */
>> class ModuleProduct extends Product {
>> /**
>> * @var \Doctrine\Common\Collections\Collection
>> * *@ORM\OneToMany(targetEntity="Module", mappedBy="product",
>> cascade={"all"}, orphanRemoval=true)*
>> * @ORM\OrderBy({"orderId" = "ASC"})
>> */
>> private $modules;
>> }
>>
>> /**
>> * @ORM\Entity
>> * @ORM\Table(name="module")
>> * @ORM\InheritanceType("JOINED")
>> * @ORM\DiscriminatorColumn(name="type", type="string")
>> */
>> abstract class Module {
>>
>> /**
>> * @var \FourTeachers\SchuldruckBundle\Entity\ModuleProduct
>> * @ORM\ManyToOne(targetEntity="ModuleProduct", inversedBy="modules")
>> * @ORM\JoinColumn(name="product_id", nullable=true)
>> */
>> private $product;
>>
>> }
>>
>> Now when I try to delete a certain ModuleProduct entity, I get the
>> following error:
>>
>> \DBALException: An exception occurred while executing 'DELETE FROM
>> product WHERE id = ?' with params [9]: SQLSTATE[23000]: Integrity
>> constraint violation: 1451 Cannot delete or update a parent row: a foreign
>> key constraint fails (`schuldruck`.`module`, CONSTRAINT
>> `FK_C2426284584665A` FOREIGN KEY (`product_id`) REFERENCES `product_module`
>> (`id`))
>>
>> Adding some debug messages to my DoctrineEventSubscriber and viewing the
>> logs I got the following result:
>>
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.message AS
>> message2, t0.param1 AS param13, t0.param2 AS param24, t0.module_id AS
>> module_id5 FROM module_error t0 WHERE t0.module_id = ? [51] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.text AS text1,
>> t0.product_id AS product_id2, t0.placeholder_id AS placeholder_id3 FROM
>> template_variable t0 WHERE t0.product_id = ? [51] []
>> *[2014-06-11 21:21:04] app.INFO: Deleting module 51 ["doctrine"] []*
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.message AS
>> message2, t0.param1 AS param13, t0.param2 AS param24, t0.module_id AS
>> module_id5 FROM module_error t0 WHERE t0.module_id = ? [52] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.text AS text1,
>> t0.product_id AS product_id2, t0.placeholder_id AS placeholder_id3 FROM
>> template_variable t0 WHERE t0.product_id = ? [52] []
>> *[2014-06-11 21:21:04] app.INFO: Deleting module 52 ["doctrine"] []*
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.message AS
>> message2, t0.param1 AS param13, t0.param2 AS param24, t0.module_id AS
>> module_id5 FROM module_error t0 WHERE t0.module_id = ? [54] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.name AS
>> name2, t0.listed_calendar AS listed_calendar3 FROM calendar t0 WHERE
>> t0.id = ? ["42"] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.start_date
>> AS start_date2, t0.end_date AS end_date3, t0.name AS name4, t0.overlay
>> AS overlay5, t0.calendar_id AS calendar_id6 FROM calendar_event t0 WHERE
>> t0.calendar_id = ? ORDER BY t0.start_date ASC [42] []
>> *[2014-06-11 21:21:04] app.INFO: Deleting module 54 ["doctrine"] []*
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.id AS id1, t0.message AS
>> message2, t0.param1 AS param13, t0.param2 AS param24, t0.module_id AS
>> module_id5 FROM module_error t0 WHERE t0.module_id = ? [53] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: SELECT t0.text AS text1,
>> t0.product_id AS product_id2, t0.placeholder_id AS placeholder_id3 FROM
>> template_variable t0 WHERE t0.product_id = ? [53] []
>>
>> *[2014-06-11 21:21:04] app.INFO: Deleting module 53 ["doctrine"]
>> [][2014-06-11 21:21:04] app.INFO: Deleting product... ["doctrine"] []*
>> [2014-06-11 21:21:04] doctrine.DEBUG: "START TRANSACTION" [] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: DELETE FROM product_error WHERE id
>> = ? [235] []
>> [2014-06-11 21:21:04] doctrine.DEBUG: DELETE FROM module_error WHERE id =
>> ? [428] []
>>
>> *[2014-06-11 21:21:04] doctrine.DEBUG: DELETE FROM module WHERE id = ?
>> [54] [][2014-06-11 21:21:04] doctrine.DEBUG: DELETE FROM product WHERE id =
>> ? [9] []*
>> [2014-06-11 21:21:04] doctrine.DEBUG: "ROLLBACK" [] []
>>
>> The "Deleting module..." and "Deleting product..." log-messages have been
>> logged in the preRemove listener.
>> This shows that modules 51, 52 and 53 were deleted *before* deletion of
>> the product.
>>
>> But in spite of that just module 54 actually gets deleted before the
>> product, resulting in a constraint violation.
>> PLEASE HELP ME !
>> I don't know where to look for a solution any more.
>>
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.