I want to set my registration call within User entity registration call should receive iso code that is field in Country entity. The system will find country by iso code and set it in User. So country in User is relation to Country entity.
It returns null when it should return some value..
My register api call..
public function registerUser($country)
{
$user = new User();
$country = $this->findCountry(['iso']);
$user->setCountry($country);
$this->em->persist($user);
$this->em->flush();
return $user;
}
And an api call for my Country entity..
public function findCountry($iso)
{
$country = $this->getCountryRepository()->findBy([
'iso' => $iso
]);
}
and my user enitty class
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"user_data"})
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Country")
* @JoinColumn(name="country_id", referencedColumnName="id")
*/
private $country;
Your registerUser method probably needs to have the iso as a parameter and not the country
And then you should pass that iso as a parameter to your findCountry call instead of passing the literal 'iso' that probably does not correspond to any countries.
That is why you get no values from the repository.