Thinkphpp6 usage problem record


This article documents some of the problems with using tp6

Business issues that confuse my eyes

Today, when I use transactions, I need to write multiple tables. One of the tables can’t write the UUID, but the other tables are successfully written, which makes me doubt my life for a time. I suspected that there was something wrong with the way I used it, so I changed the three methods to use transactions. However, save() always returned true, but the database was not updated successfully. After a few minutes of silence, I decided to turn on Xdebug.

Let me show you my configuration first

Protected $schema; this model property does not contain the field I need to update
Protected $Updatetime ='updatetime '; automatic timestamp

After my Soha found a problem, let’s call the process

$memberModel = new Member();
$members = $memberModel->find(1);
$members->uuid = '666';

Here is the call chain executed by save()
Updatedata() this is the real update method
Check allowfields() here to check whether the field is allowed to be written
Update() finally goes to this method. The fields I need to modify still exist
Parsedata() data analysis function, through the Soha of this method, I need to update the field Soha. The remaining fields that need to be updated are automatic timestamps

Final generated SQL

UPDATE ts_member SET updatetime = 1678016650

So there is no problem with transactions and updates. Just delete the $schema attribute or add this field to the property. So why don’t I just look at the SQL log? Sb!!! It should prompt that the UUID field does not exist in the $schema attribute. So I don’t have to debug the code.
Continued: after careful consideration, it is really the problem of self-use, which is not the problem of ORM design.