我想在用户实体中设置注册呼叫 注册电话应该收到国家/地区实体中的iso代码。 系统将通过ISO代码查找国家/地区,并将其设置在“用户”中。 因此,用户中的国家与国家实体有关。
当它应该返回一些值时,它返回null。
我的注册api调用。
public function registerUser($country)
{
$user = new User();
$country = $this->findCountry(['iso']);
$user->setCountry($country);
$this->em->persist($user);
$this->em->flush();
return $user;
}
然后是我的国家/地区实体的api调用。
public function findCountry($iso)
{
$country = $this->getCountryRepository()->findBy([
'iso' => $iso
]);
}
和我的用户enitty类
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;
答案 0 :(得分:0)
您的registerUser方法可能需要使用iso作为参数,而不是国家/地区
然后您应该将该iso作为参数传递给findCountry调用,而不是传递可能与任何国家都不对应的文字“ iso”。
这就是为什么您没有从存储库中获取任何值的原因。