2012-08-01 4 views
0

에 doctrine2에서 개체의 모음을 추가 할 수 있습니다어떻게 내가 가진 주요 기업

class user 
{ 
    @manytomany  
    private $countries 
} 

class country { 
    @manytomany 
    private $user 
} 

새 사용자가 다음을 만들 때 지금은에 국가의 미리 정의 된 목록을 추가 할 사용자

$countries = $em->getRepository(Country)->findBy(array('population'=>'2000'))

난 내가 그 모든 추가 할 수있는 방법을 알고 싶어요 사용자 개체의 국가

그것은

$user->addCountry($countries)

+0

(http://mattgemmell.com/2008/12/08/what-have-you-tried/) –

+0

아니라 내가 인터넷에 8 시간 보내고 그것에 대해 검색 아무것도 찾을 수 없습니다. – user17

답변

0

가 작동합니까 수 있습니까? [당신이해야 할 시도 무엇?]

class user 
{ 
    private $countries; 
    public function addCountries($countries) { 
     foreach ($countries as $country) { 
      $this->countries[] = $country; 
     } 
    } 
}