New model in new context not saving
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
New model in new context not saving
I have been able to create a model in my extension. In my project which references my extension, I'm able to get model and query the database successfully.
What I'm not understanding is why I'm not able to save a record. There is no exception (it is in a try/catch just to be sure)
Key Details:
What I'm not understanding is why I'm not able to save a record. There is no exception (it is in a try/catch just to be sure)
Code: Select all
try {
// see if seasons works
$seasonManager = MShop::create($context, 'season');
$search = $seasonManager->filter(true);
$search->slice(0, 10000);
$seaons = $seasonManager->search($search);
Log::info('Seasons found: ' . json_encode($seaons));
$newitem = $seasonManager->create([
'name' => '2024 Season - March 3x3',
'code' => '2024spring3x3',
'status' => 1,
]);
$newitems = $seasonManager->save($newitem);
Log::info('Seasons created: ' . json_encode($newitems));
}
catch (\Exception $e) {
Log::error($e->getMessage());
}
- Model is here (inside my extension): ./src/MShop/Season/Manager/Standard.php. It is the copy of the example in the docs
Code: Select all
namespace Aimeos\MShop\Season\Manager; class Standard extends \Aimeos\MShop\Common\Manager\Base implements \Aimeos\MShop\Common\Manager\Iface { public function getSaveAttributes() : array { return $this->createAttributes( [ 'name' => [ 'type' => 'string', 'required' => true, 'unique' => false ], 'code' => [ 'type' => 'string', 'required' => true, 'unique' => true ], 'status' => [ 'type' => 'int', 'required' => true ], ] ); } }
- The table is mshop_season - which all seemed to work as expected
- I have changed the logging to level 7, but I'm not seeing anything in the logs that would tell me what the problem is
Re: New model in new context not saving
Passing data directly to the create() method doesn't set the internal modified state so save() skips sending the data to the database. Use fromArray() instead:
Code: Select all
$data = [
'name' => '2024 Season - March 3x3',
'code' => '2024spring3x3',
'status' => 1,
];
$newitem = $seasonManager->create()->fromArray( $data );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star