I have a table with only 2 fields: id
(primary key) and name
. I've created a model for it, repository model.
In my repository model, there is a method save. I'm trying to create a new record in my table, executing:
$model = `$this->modelFactory->create();
$model->setName('some name');
$this->modelRepository->save($model);
Model saves succefully, but, when i try to get an id of created model, it returns null, so i have only name
inside of model ($model->getName()
=> 'some name', $model->getId()
=> null)
So, how do I get new record id?
P.S. New record appears in DB with correct id.
There is a constructor of resource model:
/**
* Initialize resource model and define main table
*
* @return void
*/
protected function _construct()
{
$this->_init('catalog_motorbike_vendors', 'id');
}
id
primary key must have'identity' => true
or'auto_increment' => true
for save autoincrement value'auto_inctement'=> true
. And it table i see correct ids for new entities.