如何选择一位特定作者的所有项目?这种方式可能吗?或者,如果我想要许多项目类型和项目包(项目有很多项目),我该如何编辑实体?
物品
/**
* @ORM\Table()
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "cd" = "ItemCD",
* "dvd" = "ItemDVD",
* "pack" = "ItemPack",
* })
*/
class Item
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=250, nullable=false)
*/
private $name;
}
物品CD
/**
* @ORM\Table()
* @ORM\Entity
*/
class ItemCD extends Item
{
/**
* @ORM\ManyToOne(targetEntity="Author", inversedBy="item")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
private $author;
}
物品DVD
/**
* @ORM\Table()
* @ORM\Entity
*/
class ItemDVD extends Item
{
/**
* @ORM\ManyToOne(targetEntity="Author", inversedBy="item")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
private $author;
}
物品包
/**
* @ORM\Table()
* @ORM\Entity
*/
class ItemPack extends Item
{
/**
* @ORM\ManyToMany(targetEntity="Item", inversedBy="item")
* @ORM\JoinTable()
*/
private $items;
}
作者
/**
* @ORM\Table()
* @ORM\Entity
*/
class Author
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=250, nullable=false)
*/
private $name;
}