I have two entities, Item and SpecialItem
SpecialItem extends Item, where Item is normal shopping item with price property, and the SpecialItem is a shopping item on sale with extra discount property.
I'm using Class Table Inheritance
The Item:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Item
*
* @ORM\Table(name="item")
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="item_type", type="string")
* @ORM\DiscriminatorMap({"item" = "Item", "special" = "SpecialItem"})
*/
class Item
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="price", type="decimal", precision=10, scale=0, nullable=false)
*/
private $price;
/**
* @var string
*
* @ORM\Column(name="description", type="text", length=65535, nullable=true)
*/
private $description;
}
The Special Item :
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class SpecialItem extends Item
{
/**
* @var string
*
* @ORM\Column(name="discount", type="decimal", precision=10, scale=0, nullable=false)
*/
private $discount;
}
If I created a SpecialItem and persisted it (now it has one row in table item and one row in table specialitem with discount value), and now I decided to remove the discount so the special item will now be a normal item.
How can I remove the discount related rows only not the whole item and change the DiscriminatorColumn to reflect the parent type Item ?