I have a crazy issue that my record in the database is not getting saved.
- I’ve made a customer module. Which has model
OrderParams.php
<?php
namespace VendorModuleModel;
use MagentoCronException;
use MagentoFrameworkModelAbstractModel;
class RequestParams extends AbstractModel
{
/**
* @var MagentoFrameworkStdlibDateTime
*/
protected $_dateTime;
/**
* @return void
*/
protected function _construct()
{
$this->_init(VendorModuleModelResourceModelOrderParams::class);
}
}
ResourceMode/OrderParams.php
<?php
namespace VendorModuleModelResourceModel;
use MagentoFrameworkModelResourceModelDbAbstractDb;
class OrderParams extends AbstractDb
{
/**
* Initialize resource
*
* @return void
*/
public function _construct()
{
$this->_init('orders_params', 'id');
}
}
-
So if i use model for saving a record
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$reqParams=$objectManager->create(‘VendorModuleModelOrderParams’);try { /*$reqParams->setData([ 'order_id' => 1, 'company_id' => 1 ]);*/ $reqParams->setOrderId(1); $reqParams->setCompanyId(1); $reqParams->save(); } catch (MagentoFrameworkExceptionLocalizedException $e) { $aa=$e->getMessage(); }
So if you see above i have tried both ways .
And i have tried this with or without object manager as well. Still no luck. It doesn’t even say that anything went wrong . It returns result as TRUE.
SO i decided to do it with direct sql query
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$insertData[] = ['order_id' => 14, 'company_id' => 1];
$insertData[] = ['order_id' => 14, 'company_id' => 2];
try {
$connection->beginTransaction();
$connection->insertMultiple('orders_params', $insertData);
$connection->commit();
} catch(Exception $e) {
$connection->rollBack();
}
And i did it with insertMultiple() and direct SQL string query and insertArray()..
All went failed and all have common issue that they say that its successfully done But when i go to DB table its empty.
Surprising thing is when i copy the generated query from $VARIABLE using XDEBUGGER and run it directly in sql server . It successfuly gets inserted.
One more surprising thing if i fail any integrity constracint in my query. It says that query have issue and mysql will not insert it.
Then i tried this in my other class which is basically a CARRIER model . And there it worked without having any change in the code. Just by copying and pasting it there.
But in my model its doing nothing .
Then i noticed in the database that if i put a record manually its has different auto increment id . So basically what i found out every time i try to insert record. It gets inserts in table. But somehow it gets deleted automatically ..
For the confirmation i turned on QUERY LOGGER in phpmyadmin and i found out my query there for inserting . But i did not find any delete query .. But still its getting vanished after inserting somehow .
So can anyone help me out solving this issue ?