0

I have the

class user 
{
    @manytomany    
    private $countries
}

and

class country {
    @manytomany
    private $user
}

Now when the new user is created then i want to add predefined list of countries to user

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

I want to know how can i add those all countries in user entity

Is it possible

$user->addCountry($countries)

user17
  • 383
  • 2
  • 4
  • 17

1 Answers1

0

Will it work?

class user
{
    private $countries;
    public function addCountries($countries) {
        foreach ($countries as $country) {
            $this->countries[] = $country;
        }
    }
}
WizardZ
  • 1,372
  • 13
  • 12