이것을 Class Table Inheritance이라고합니다. 부모 엔티티와이를 확장하는 하위 엔티티를 가질 수 있습니다. 추가 필드는 자녀의 테이블에 저장되고 기본 키는 상위 테이블에 링크됩니다.
다음은 기존 코드의 기본 예제입니다. 사용자가 원하는대로 수정할 수 있습니다. 나는 접근 자 메소드를 제외시켰다.
똥! CTI를 사용할 때 속성을 protected
으로 설정해야하며 비공개로 설정하면 공유 할 수 없습니다.
부모 클래스
/**
* Item
*
* @ORM\Table(name="`item`")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type_hint", type="string")
* @DiscriminatorMap({"physical_item" = "PhysicalItem"})
* @ORM\Entity(repositoryClass="\Acme\MainBundle\Entity\ItemRepository")
*/
class Item
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
protected $name;
}
자식 테이블이 항목 테이블과 physical_item 테이블이 것이 예에서
/**
* PhysicalItem
*
* @ORM\Table(name="`physical_item`")
* @ORM\Entity
*/
class PhysicalItem extends Item
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="weight", type="string", length=255, nullable=true)
*/
protected $weight;
}
. 항목의 모든 속성은 여기에 저장되며 physical_item의 추가 속성은 자체 테이블에 저장됩니다. Entity 클래스를 사용하면 모든 속성에 액세스 할 수있게됩니다.