0

我有

class user 
{
    @manytomany    
    private $countries
}

class country {
    @manytomany
    private $user
}

现在,当创建新用户时,我想向用户添加预定义的国家列表

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

我想知道如何在用户实体中添加所有国家

可能吗

$user->addCountry($countries)

4

1 回答 1

0

它会起作用吗?

class user
{
    private $countries;
    public function addCountries($countries) {
        foreach ($countries as $country) {
            $this->countries[] = $country;
        }
    }
}
于 2012-08-01T17:20:54.910 回答