2017-04-13 25 views

回答

0

您需要使用DISTINCT條款:https://www.w3schools.com/sql/sql_distinct.asp

這裏是如何從一個控制器做到這一點:

$qb = $em->getRepository("MyBundle:Country")->createQueryBuilder("c"); 

$countries = $qb->select("c") 
    ->distinct(true) 
    ->getQuery() 
    ->getResult(); 

一個班輪:

$countries = $em->getRepository("MyBundle:Country")->findBy(array('distinct' => true)); 

但是如果我是你我會創建一個獨特的國家實體,並在用戶和國家之間建立ManyToOne關係。這將是一個更清潔的解決方案IMO

相關問題