CAKEPHP 4-与协会一起保存

发布于 2025-01-24 23:11:24 字数 318 浏览 4 评论 0原文

我在保存与关联的数据方面有问题。问题在于,我在后卫上做事,关联正在触发主要实体($ tosave)。这是正常的吗? 就像首先保存关联,然后是主要实体。是否改变了储蓄顺序?有意义吗?

$toSave = $this->{MODEL_NAME}->patchEntity($toSave, $postData, ['associated' => ['SomeAssociation']]);
if ($this->{MODEL_NAME}->save($toSave)) {

}

版本:Cakephp 4.x

谢谢。

I am having problems with saving data with associated. The problem is that i'm do thing on AfterSave and the associations are triggering the AfterSave before the principal entity($toSave). This is normal?
It's like first save the associations then the principal entity. Is a way of changing the order of saving? Makes sense?

$toSave = $this->{MODEL_NAME}->patchEntity($toSave, $postData, ['associated' => ['SomeAssociation']]);
if ($this->{MODEL_NAME}->save($toSave)) {

}

Version: Cakephp 4.x

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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