【问题标题】:CakePHP patchEntity() and save() not updating specific fields in databaseCakePHP patchEntity() 和 save() 不更新数据库中的特定字段
【发布时间】:2020-05-30 16:55:52
【问题描述】:

所以我在 Orders 表中添加了一些额外的字段,payment_typeorder_status

我已将它们添加到相关模型的 Accessible 数组中,但在 Save() 之后,我没有看到数据库中填充了这两个字段。这里会发生什么?

FWIW,这是 Save() 返回的 print_r():

App\Model\Entity\Order Object
(
   [grand_total] => 99.99
   [payment_type] => Paypal
   [order_status] => Accepted
   [transaction_id] => 123
   [[new]] => 
   [[accessible]] => Array
       (
           [grand_total] => 1
           [payment_type] => 1
           [order_status] => 1
           [transaction_id] => 1
       )

   [[dirty]] => Array
       (
       )

   [[original]] => Array
       (
       )

   [[virtual]] => Array
       (
       )

   [[hasErrors]] => 
   [[errors]] => Array
       (
       )

   [[invalid]] => Array
       (
       )

   [[repository]] => Orders
)

但奇怪的是,当我在本地环境中运行此命令时,它会毫无问题地更新这些列。实时服务器和我的本地是重复的存储库,所以它必须是数据库或服务器配置设置?而且,我在日志中找不到任何指向任何错误的内容。

有什么想法吗?

【问题讨论】:

    标签: php database cakephp model save


    【解决方案1】:

    原来我的实时环境 ORM 缓存仍在反映旧模式。

    直到现在我都不知道这是一件事,老实说,我对不理解 /why/ 感到非常沮丧。我将不得不对此进行一些阅读以更好地理解。

    对于将来遇到类似问题的任何人,请交叉检查有问题的环境的“/tmp/cache/models/”文件夹,然后删除或更新有问题的表架构文件。

    【讨论】:

    猜你喜欢
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多