Save data to DB happened in weired way(Solved)

Greetings, I’m new to this community and Cakephp.
I was trying to save data to my database(MySQL).

Here’s my db structure
螢幕擷取畫面 2023-03-21 153602

and here’s my code

        $connection = ConnectionManager::get('default');
        $connection->begin();

        $indexData = [
            "customer_id" => 555,
            "zip_code" => 1,
            "address" => 2,
            "ship_fee" => 3,
            "discount" => 4,
        ];
        $entity = $this->OrderIndex->newEntity($indexData);
        $res = $this->OrderIndex->save($entity);
        $connection->commit();

but only “customer_id” will be stored, but others will not.

I figured it out myself.
CakePHP has cache for models.
Once I cleared it, it works just fine.

Nice that you have found the solution yourself :+1:

I just wanted to inform you, that CakePHP does transactions automatically when saving entities.

So you don’t need to manually do

$connection = ConnectionManager::get('default');
$connection->begin();
// Other code
$connection->commit();

but this

$indexData = [
    "customer_id" => 555,
    "zip_code" => 1,
    "address" => 2,
    "ship_fee" => 3,
    "discount" => 4,
];
$entity = $this->OrderIndex->newEntity($indexData);
$res = $this->OrderIndex->save($entity);

will automatically create a transaction

See Saving Data - 4.x

When saving, CakePHP will apply your rules, and wrap the save operation in a database transaction.