0
我有兩個相關的實體,我需要一個查詢來檢查entityOne是否有兩個不同的關係(額外的列作爲diff字段)到entityTwo。其中存在兩個關聯的主義2查詢
一個簡單的「WHERE entityTwo.diff_field = 1 AND entityTwo.diff_field = 2」不起作用。
我怎樣才能實現這一目標?
感謝
UPDATE:
$query = $this->createQueryBuilder('one');
$query->addSelect('two')->leftJoin('one.two', 'two');
$query->where('two.id = :a')->setParameter('a',1);
$query->andWhere('two.id = :b')->setParameter('b',2);
EntityOne
class EntityOne {
/**
* @ORM\Id
* @ORM\Column(type="integer", nullable=false);
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="EntityTwo", mappedBy="one")
*/
protected $two;
}
EntityTwo
class EntityTwo {
/**
* @ORM\Id
* @ORM\Column(type="integer", nullable=false);
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="EntityOne", inversedBy="two", cascade={"persist"})
* @ORM\JoinTable(name="one_two_xref")
*/
protected $one;
}
向我們展示您的數據庫方案並告訴關於mysql/mssql/oracle/postgresql? – FSou1
@ FSou1已更新。 – MGP