我有这个实体:
/**
* @ORM\Entity
* @ORM\Table(name="person")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "natural" = "NaturalPerson",
* "legal" = "LegalPerson"
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Person {
use IdentifiedAutogeneratedEntityTrait;
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Column(name="description", type="string", length=250, nullable=false)
*/
protected $description;
/**
* @ORM\Column(name="contact_person", type="string", length=250, nullable=true)
*/
protected $contact_person;
/**
* @ORM\Column(name="person_type", type="integer", nullable=false)
*/
protected $person_type = 1;
/**
* @ORM\OneToMany(targetEntity="Orders", mappedBy="person")
* */
protected $orders;
/**
* @ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
protected $deletedAt;
}
我在这里使用了Doctrine Table Inheritance,所以我想使用Nelmio Alice
为该实体创建一个测试套件,我应该如何处理discr
列?我的意思是我怎么对Alice说要使用哪种类型?我试过这个:
FrontendBundle\Entity\Person:
Person{1..10}:
description: <text(15)>
contact_person: <text(75)>
person_type: <randomElement(array('1','2'))>
discr: <randomElement(array('natural','legal'))>
但由于discr
不是Person
实体上的专栏,有什么建议可以吗?
答案 0 :(得分:1)
这是一个有趣的边缘案例。我看到两个可能的解决方案:
自己创建两种不同类型的实体,即
FrontendBundle\Entity\NaturalPerson:
Person{1..5}:
description: <text(15)>
contact_person: <text(75)>
person_type: <randomElement(array('1','2'))>
FrontendBundle\Entity\LegalPerson:
Person{6..10}:
description: <text(15)>
contact_person: <text(75)>
person_type: <randomElement(array('1','2'))>
或者为了保持简短并避免重复,您可以使用继承:
FrontendBundle\Entity\Person:
person (template):
description: <text(15)>
contact_person: <text(75)>
person_type: <randomElement(array('1','2'))>
FrontendBundle\Entity\NaturalPerson:
Person{1..5} (extends person):
FrontendBundle\Entity\LegalPerson:
Person{6..10} (extends person):
如果这些都不起作用,请在github上报告,以便我们找到解决方案。