我有以下实体:
// AppBundle/Entity/Contacts.php
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="Nominations", mappedBy="contact")
**/
private $nominations;
// AppBundle/Entity/Nominations.php
/**
* @var Contacts
*
* @ORM\ManyToOne(targetEntity="Contacts", inversedBy="nominations")
**/
private $contact;
/**
* @var Votes
*
* @ORM\OneToMany(targetEntity="Votes", mappedBy="nomination")
**/
private $votes;
// AppBundle/Entity/Votes.php
/**
* @var Nominations
*
* @ORM\ManyToOne(targetEntity="Nominations", inversedBy="votes")
**/
private $nomination;
使用Contacts实体中的以下方法,该实体循环通过提名记录并将它们填充到我想在ContactsAdmin中显示的ArrayCollection中:
// AppBundle/Entity/Contacts.php
/**
* Get Votes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getVotes()
{
$return = array();
foreach ($this->getNominations() as $nom) {
$return = array_merge($return, $nom->getVotes()->toArray());
}
return new ArrayCollection($return);
}
// AppBundle/Admin/ContactsAdmin.php
$formMapper
->add('votes', 'sonata_type_collection', array(
'required' => false,
'by_reference' => false
), array(
'data_class' => 'AppBundle\Entity\Votes',
'admin_code' => 'app.admin.votes', //this is a VotesAdmin service which works fine on its own
'edit' => 'inline',
'inline' => 'table',
));
但是我收到了这个错误:
当前字段
votes
未链接到管理员。请为目标实体创建一个:``
注意实体名称是空白的。我已经尝试了各种不同的选项组合,但我不断回到同样的问题:Sonata无法弄清楚实体类和相关的管理员是什么,即使我已经指定了它。