Skip to main content
added 261 characters in body
Source Link
Styopchik
  • 177
  • 2
  • 16

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');
}

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.

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');
}
added 12 characters in body; edited tags
Source Link
Prince Patel
  • 22.9k
  • 10
  • 98
  • 121

I have a table with only 2 fields: id (primary key) and nameid (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 iI get new record id?

P.S. New record appears in DB with correct id.P.S. New record appears in DB with correct id.

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.

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.

Source Link
Styopchik
  • 177
  • 2
  • 16

Saved custom model doesn't returns it's id

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.