我有一个简单的实体
/**
* @ORM\Entity(repositoryClass="...\Repository\UserTestRepository")
* @ORM\Table(name="users", uniqueConstraints={
* @ORM\UniqueConstraint(name="U_email", columns={"email"})
* })
* @UniqueEntity("email", message="Email is already used!")
*/
class UserTest
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string", length=180)
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $email;
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank()
*/
protected $jobTitle;
/**
* @var Company
* @ORM\ManyToOne(targetEntity="...\Entity\Company", fetch="EAGER")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private $company;
public function getId()
{
return $this->id;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function getJobTitle()
{
return $this->jobTitle;
}
public function setJobTitle($jobTitle)
{
$this->jobTitle = $jobTitle;
return $this;
}
public function setCompany(...\Entity\Company $company = null)
{
$this->company = $company;
return $this;
}
public function getCompany()
{
return $this->company;
}
}
和控制器
$repo = $this->getDoctrine()->getRepository('..\Entity\UserTest');
$user = $repo->find(519);
dump($user);
$user->setJobTitle('new value');
$user->setCompany(null);
dump($user);
$repo->findBy(['email' => 'test@test.com']);
dump($user);
第一档转储,原始
第二次转储,更改后不刷新
第三次转储,在findBy之后,jobTitle –具有新值,公司–原始值,更改丢失
这是正常的学说行为还是错误?我使用的是教义/规范v2.5.11。在新版本中修复了吗?
任何帮助,请
答案 0 :(得分:1)
通过存储库的findBy()查找未损坏的实体时,这是教义的正常行为。请参阅https://github.com/doctrine/orm/issues/5092以获取更多信息。