Make load auto_increment after saving

I am using Doctrine to abstract the database. Now I want to get the primary key auto_incrementfrom the newly created object (and save()'d), but it $obj->toArray()shows me that after the call save()this field is empty.

Is there a flag that I don't know about this? Or do I really need to query an object from a database?

+3
source share
2 answers

Make sure that you have the auto-increment flag set when setting up the object in the method setTableDefinition()(or in the corresponding YAML configuration file). If this flag is not set, Doctrine will not know to update it. You should have something similar to this:

 $this->hasColumn('id', 'integer', 4, array(
                  'type' => 'integer',
                  'length' => 4,
                  'fixed' => false,
                  'unsigned' => true,
                  'primary' => true,
                  'autoincrement' => true //this flag right here
             )
 );
+3

refresh toArray.

0

Source: https://habr.com/ru/post/1727168/


All Articles