数据标记为脏的数据,即使它没有更改

发布于 2025-01-24 14:45:04 字数 656 浏览 5 评论 0原文

即使我对现有字段的相同价值影响相同,但它被标记为肮脏。

注意:直接分配值的原因是因为我正在从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文