我是奏鸣曲管理员的新手,这可以在一个管理员类中使用两个实体吗?
我的用户实体,
App\MyBundle\Entity\Users.php
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=45, nullable=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=100, nullable=true)
*/
private $email;
我的 UserProject 实体,
App\MyBundle\Entity\UserProjects.php
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var \User
*
* @ORM\ManyToOne(targetEntity="Users")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="userId", referencedColumnName="id")
* })
*/
private $userid;
/**
* @var array
*
* @ORM\Column(name="projectId", type="array")
*/
private $projects;
我的管理课,
class UserAdmin extends SonataUserAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General') // these fields from Users Entity
->add('username')
->add('email')
->with('Projects') // these fields from UserPrjects Entity
/* here i need to add a field for projects related to current user */
}
}
有没有办法让这两个实体连接在一起?