0
我使用symfony 2.7并使用SonataAdminBundle。sonata_type_model中的默认数据
我有2个实体叫做(Produit)和(对应)与OneToMany的关系,一个产品可以有很多的对应关系。在创建了(Produit)形式我有correspondants添加许多(通讯员),我喜欢在默认情况下添加所有Correspondants,对于我试着这样做:
ProduitAdmin
$query = $this->modelManager->getEntityManager(new User())->createQuery("SELECT s FROM UserBundle\Entity\User s WHERE s.type LIKE 'Correspondant'");
$formMapper
->add('correspondants','sonata_type_model', array(
'class'=>'Devagnos\UserBundle\Entity\User',
'multiple'=> true,
'by_reference' => false,
'label'=>'Correspondants associés',
'data' => function() {
$data = new ArrayCollection();
$r= $query->getResult();
foreach($r as $result) {
$data->add($result->getId());
}
return $data;
},
'query' => $query),
)
但这不起作用,
有人可以帮我吗?谢谢
谢谢@miikes,我只是改变:$ selected = $ query-> getResult() –