假設我有實體:class UserEntity{ /** * @var integer * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * @ORM\Column(type="string") */ private $name; /** * @var string * @ORM\Column(type="string") */ private $email;// and contruct, getters and setters..}并在相應的服務中:class UserService extends BaseService{ public function update($id, $data) { try { $user= $this->fetch($id); if (! $user instanceof UserEntity) { // throw respective exception; } $user->setName($data['name']); $user->setEmail($data['email']); $this->entityManager->flush($user); return $user; } catch (Exception $e) { throw $e; } }}如果有這樣的用戶:{ id: 1, name: jhon, email: [email protected]}并且提供給服務的數據是:$id = 1;$data = [ 'name' => jhon, 'email => jhon@domain,com]那么,在這些情況下,避免對數據庫進行不必要的查詢的最佳方法是什么?因為沒有必要調用 flush 方法。還是 Doctrine 內部負責不做查詢?
- 1 回答
- 0 關注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消