Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PredefinedId.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
20 trait PredefinedId
21 {
31  protected function isObjectNotNew(AbstractModel $object)
32  {
33  $connection = $this->getConnection();
34  $select = $connection->select()
35  ->from($this->getMainTable(), [$this->getIdFieldName()])
36  ->where($this->getIdFieldName() . ' = ?', $object->getId())
37  ->limit(1);
38  return (bool)$connection->fetchOne($select);
39  }
40 
51  protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
52  {
53  $bind = $this->_prepareDataForSave($object);
54  $this->getConnection()->insert($this->getMainTable(), $bind);
55 
56  if ($this->_isPkAutoIncrement) {
57  $object->setId($this->getConnection()->lastInsertId($this->getMainTable()));
58  }
59 
60  if ($this->_useIsObjectNew) {
61  $object->isObjectNew(false);
62  }
63  }
64 }
$connection
Definition: bulk.php:13