数据标记为脏的数据,即使它没有更改
即使我对现有字段的相同价值影响相同,但它被标记为肮脏。
注意:直接分配值的原因是因为我正在从Excel文件中导入数据,并在需要时通过编程更新行。
$request = $this->Requests->get(123);
//existing field is "ABC123"
$request->field = 'ABC123';
//field will be set as dirty, even if the content is the same
debug($request->getDirty());
输出:
[
(int) 0 => 'field',
]
是否有内置功能可以比较数据,而不会标记该字段与数据没有更改一样脏?也许有现有插件?
否则,它可能涉及编写所有这些做到所有这些的行为beforesave
?
解决方案:
$patch = ['field' => 'ABC123'];
$request = $this->Requests->patchEntity($request, $patch);
//isDirty() is false!
Even though I'm affecting the same value to an existing field, it's being marked as dirty.
Note: The reason for direct assignment of values is because I'm importing data from an Excel file and programmatically updating rows where needed.
$request = $this->Requests->get(123);
//existing field is "ABC123"
$request->field = 'ABC123';
//field will be set as dirty, even if the content is the same
debug($request->getDirty());
Output:
[
(int) 0 => 'field',
]
Is there built-in functionality that would compare the data and not mark the field as dirty as the data didn't change? Perhaps there's an existing plugin?
Otherwise, it probably involves writing a behavior overriding beforeSave
that does all of this?
Solution:
$patch = ['field' => 'ABC123'];
$request = $this->Requests->patchEntity($request, $patch);
//isDirty() is false!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论