我的更新无法更新关系实体数据库中的记录。我有两个名为user和user_meta的实体,因为一个用户可以只使用一个user_meta记录我使用OneToOne,如果我理解这个概念应该是正确的。
用户的更新数据已更新,但对于UserMeta没有任何反应。
用户实体
quux.js
UserMeta实体
<?php
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Table(name="users", indexes={@ORM\Index(name="email", columns={"email"})})
* @ORM\Entity(repositoryClass="UserRepository")
*/
class User {
/**
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
*
* @ORM\Column(name="email", type="string", nullable=false, length=125)
*/
protected $email;
/**
*
* @ORM\Column(name="password", type="string", nullable=false, length=125)
*/
protected $password;
/**
*
* @ORM\Column(name="role", type="string", nullable=false, length=25)
*/
protected $role;
/**
*
* @ORM\Column(name="status", type="string", nullable=false, length=10)
*/
protected $status;
/**
*
* @ORM\Column(name="created", type="datetime")
*/
protected $created;
/**
*
* @var $userMeta
*
* @ORM\OneToOne(targetEntity="UserMeta", mappedBy="user")
*/
protected $userMeta;
/**
*
* Get id
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
*
* Set email
* @param $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
*
* Get email
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
*
* Set password
* @param $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
*
* Get password
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
*
* Set role
* @param $role
*/
public function setRole($role)
{
$this->role = $role;
}
/**
*
* Get role
* @return mixed
*/
public function getRole()
{
return $this->role;
}
/**
*
* Set status
* @param $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
*
* Get status
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* Set created
* @param $created
*/
public function setCreated(\DateTime $dateTime)
{
$this->created = $dateTime;
}
/**
*
* Get created
* @return mixed
*/
public function getCreated()
{
return $this->created;
}
/**
* @return mixed
*/
public function getUserMeta()
{
return $this->userMeta;
}
/**
* @param mixed $userMeta
*/
public function setUserMeta(UserMeta $userMeta)
{
$this->userMeta = $userMeta;
}
}
在调用flush之前转储
<?php
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Table(name="users_meta")
* @ORM\Entity(repositoryClass="UserRepository")
*/
class UserMeta {
/**
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
*
* @ORM\Column(name="first_name", type="string", nullable=true, length=125)
*/
protected $firstName;
/**
*
* @ORM\Column(name="last_name", type="string", nullable=true, length=125)
*/
protected $lastName;
/**
*
* @ORM\Column(name="gender", type="string", nullable=true, length=5)
*/
protected $gender;
/**
* @var User $user
* @ORM\OneToOne(targetEntity="User", inversedBy="user")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param mixed $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return mixed
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param mixed $lastName
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
/**
* @return mixed
*/
public function getGender()
{
return $this->gender;
}
/**
* @param mixed $gender
*/
public function setGender($gender)
{
$this->gender = $gender;
}
/**
*
* Get user
* @return mixed
*/
public function getUser()
{
return $this->user;
}
/**
*
* Set user
* @return mixed
*/
public function setUser($user)
{
$this->user = $user;
return $this->user;
}
}
控制器
object(Application\Entity\User)[368]
protected 'id' => int 50
protected 'email' => string 'name@domain.com' (length=22)
protected 'password' => string 'BCRYPT_HASH' (length=60)
protected 'role' => string 'admin' (length=5)
protected 'status' => string 'active' (length=6)
protected 'created' =>
object(DateTime)[359]
public 'date' => string '2017-01-08 10:59:55.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Amsterdam' (length=16)
protected 'userMeta' =>
object(Application\Entity\UserMeta)[373]
protected 'id' => int 2
protected 'firstName' => string 'Ivanovic' (length=5)
protected 'lastName' => string 'Tzazinsky' (length=7)
protected 'gender' => string 'male' (length=4)
protected 'user' =>
&object(Application\Entity\User)[368]