我有两个实体
联系人:
<?php
namespace AppBundle\Entity;
use...
/**
* @ORM\Entity
* @UniqueEntity(
* fields={"client", "name", "surname"},
* errorPath="name",
* message="This contact is already in use for this client."
* )
* @ORM\Table(name="contact")
*/
class Contact
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var integer
* @Assert\NotBlank()
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(name="client_id", referencedColumnName="client_id", nullable=false)
*/
private $client;
/**
* @ORM\Column(type="string", length=255, options={"default": ""}, nullable=true)
* @Assert\NotBlank()
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, options={"default": ""}, nullable=true)
* @Assert\NotBlank()
*/
protected $surname;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Email")
* @ORM\JoinColumn(name="email_id", referencedColumnName="id")
*/
protected $email;
...
}
和电子邮件:
class Email
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(name="client_id", referencedColumnName="client_id")
*/
private $client;
/**
* @var string
*
* @ORM\Column(name="email", type="string", nullable=false)
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
...
}
我正在使用“sonata admin bundle”来生成GUI。
对于ContactAdmin,我有以下代码段:
...
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('email', 'sonata_type_model_list', array(
// 'query' => $query,
'label' => 'E-Mail',
'compound' => true,
'by_reference' => true,
))
问题:当我添加新条目或从列表中选择一个条目时 - 我不想再次选择“客户端”。它与已经选择的类似。
我能够访问pcode-Parameter以查看我是否有父类(Email-Class的Contact-Class) - 但是如何访问父母选择/选择客户端的数据-Class?