Home » Php » php – CakePHP patchEntity() and save() not updating specific fields in database

php – CakePHP patchEntity() and save() not updating specific fields in database

Posted by: admin February 25, 2020 Leave a comment

Questions:

So I have added a few additional fields to an Orders table, payment_type and order_status.

I have added them to the Accessible array for the related Model, but after a Save(), I’m not seeing the two fields populated in the Database. What could be happening here?

FWIW, here’s a print_r() of the Save() return:

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
)

Strangely though, when I run this command on my local environment, it updates those columns with no issues. Live server and my local are duplicate repositories, so it must be a database or server config setting? And, I can’t find anything in the logs pointing to any errors.

Any ideas?

How to&Answers:

Turns out my live environment ORM cache was still reflecting the old schema.

Until now I had no idea this was a thing, and honestly I’m beyond frustrated not understanding /why/. I’ll have to do some reading on this to get a better understanding.

For anyone from the future having the similar issues, cross check your buggy environment’s “/tmp/cache/models/” folder and either remove or update the table schema file in question.