2015-07-10 69 views
1

我对查询语法有疑问或问题。我有ManyToMany相关的2个实体表:Symfony查询语法

Person.php

/** 
* @ORM/ManyToMany(targetEntity="Deal", inversedBy="persons") 
* @ORM/JoinTable(name="persons_deals") 
*/
protected $deals; 

Deal.php

/* 
* @ORM/ManyToMany(targetEntity="Person", mappedBy="deals") 
*/
protected $persons; 

这将创建一个 “额外” 的数据库中的表称为persons_deals。 在该表是 “PERSON_ID”“DEAL_ID”

如果交易完成有(例如):

person_id ---- deal_id 

    1 -------------- 1 
    2 -------------- 1 

所以,如果我想要得到DEAL_ID 1连接到它。 我应该做什么样的查询?

+0

你应该看看学说(此正在使用)。你并不真正使用SQL或表,你使用对象和类。 $人─> setDeal($处理) – Koalabaerchen

回答

1

有没有这样的事情Symfony的查询语言(或语法)。 你可能在谈论教义。

所以最好在Doctrine文档中介绍如何组织多对多的关系。

http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#many-to-many-unidirectional

支付你的注意,你可能需要从固定例如命名空间,使之在你的代码

所以不是

  • @ManyToMany工作(targetEntity = “集团” )
  • @JoinTable(name =“users_groups”,

,你将需要

  • @ORM \多对多(targetEntity = “本集团”)
  • @ORM \ JoinTable(NAME = “users_groups”