【发布时间】:2013-12-24 23:00:22
【问题描述】:
我正在尝试映射一对多关系,但我有很多问题。 我有以下实体关系模型:
所以,我在 Usuario 学说模型中写下一个注释:
class Usuario implements UserInterface{
// Some code...
/**
* @ORM\OneToMany(targetEntity="UsuarioComunicacion", mappedBy="usuario")
*/
protected $contacto;
// More code...
}
在 UsuarioComunicacion 模型(N-N 表)中:
class UsuarioComunicacion{
/**
* @ORM\Id
* @ORM\Column(name="idusuario", type="integer", length=11)
* @ORM\ManyToOne(targetEntity="Usuario", inversedBy="contacto")
* @ORM\JoinColumn(name="idusuario", referencedColumnName="idusuario")
*/
protected $usuario;
// More code...
}
但是,当我尝试使用这种关系(到控制器代码中)时,Symfony 说:
"注意:未定义索引:usuario in /var/www/AppsManantiales/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php 第 1575 行"
我没有太多的映射经验...而且我不知道发生了什么。 有任何想法吗 ? 谢谢!
更新 1
当我尝试获取用户的联系人值时出现问题:
$user->getContacto();
getContacto() 是一个自动生成的 getter:
/**
* Get contacto
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getContacto()
{
return $this->contacto;
}
【问题讨论】:
-
尝试将 mappedBy="usuario" 更改为 mappedBy="Usuario",它应该可以工作
-
@Satya thnaks 回复,但不起作用:(
标签: php symfony doctrine-orm many-to-many