ManyToOne和OneToMany发行Symfony2

时间:2015-01-10 19:43:58

标签: symfony doctrine-orm

您好,实体关系存在很大问题。

我有两个实体 用户和TipoUtenti

class Users
{    
/**
 * @ORM\ManyToOne(targetEntity="TipoUtenti" inversedBy="utenti")
 **/
protected $usersus;
...

class TipoUtenti
{

 /**
 * @ORM\OneToMany(targetEntity="Users", mappedBy="usersus")
 */
protected $utenti;

public function __construct()
{
$this->$utenti = new \Doctrine\Common\Collections\ArrayCollection();
}   

如果我查看个人资料查询,我看到:

SELECT 
t0.name AS name1, 
t0.email AS email2, 
t0.id_tipo_utente AS id_tipo_utente10, 
t0.citta_id AS citta_id14, 
t0.id AS id15 
FROM 
Users t0

并且没有加入查询。

有什么问题?

1 个答案:

答案 0 :(得分:0)

您可以在这里找到解决方案Many-To-Many, Bidirectional

 /**
     * @ManyToMany(targetEntity="Group", inversedBy="users")
     * @JoinTable(name="users_groups") // this is what you've forgotten
     **/

否则,请尝试使用DQL并编写自己的查询