如何在学说中设置多个条件ManyToMany ..
模型
/**
* @ORM\ManyToMany(targetEntity="users",inversedBy="friends",cascade={"ALL"})
* @ORM\JoinTable(name="friends",
* joinColumns={@ORM\JoinColumn(name="friend_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
* )
*/
private $groupsa;
public function getusersre() {
return $this->groupsa;
}
输出
SELECT
t0.id AS id_1,
t0.email AS email_2,
t0.username AS username_3,
t0.password AS password_4,
t0.first_name AS first_name_5,
t0.last_name AS last_name_6,
t0.location AS location_7,
t0.remember_token AS remember_token_8,
t0.created_at AS created_at_9,
t0.updated_at AS updated_at_10
FROM
users t0
INNER JOIN friends ON t0.id = friends.user_id
WHERE
friends.friend_id = ?
我希望它像这样
WHERE
friends.friend_id = ?
or friends.xxxx_id = ?
等待回应,谢谢所有人......
答案 0 :(得分:0)
你可以按照@SergioIvanuzzo的建议去做,但是如果你想在你的实体中这样做,你也可以使用教义Doctrine\Common\Collections\Criteria
类。您可以在文档章节 8.8. Filtering Collections 中阅读所有相关内容。
public function getFriends(){
$id = 1; // ...the id you want to use for filtering
$criteria = Criteria::create()
->where(Criteria::expr()->eq("xxxx_id", $id));
return $this->friends->matching($criteria);
}