Jaimin의 답변을 명확히하기 위해 :
이것은 모든 엔티티에서 작동합니다.
사실이 아닙니다. 확장되는 EAV 엔터티에만 작동합니다.Magento\Eav\Model\Entity\AbstractEntity
자원 모델이 확장되는 비 EAV 엔티티를 처리하는 경우 자원 모델 Magento\Framework\Model\ResourceModel\Db\AbstractDb에서 saveAttribute메소드 를 구현 해야합니다.
마 젠토 2에서는 다음과 같이 Magento\Sales\Model\ResourceModel\Attribute수업을 진행했습니다 .
public function saveAttribute(AbstractModel $object, $attribute)
{
if ($attribute instanceof AbstractAttribute) {
$attributes = $attribute->getAttributeCode();
} elseif (is_string($attribute)) {
$attributes = [$attribute];
} else {
$attributes = $attribute;
}
if (is_array($attributes) && !empty($attributes)) {
$this->getConnection()->beginTransaction();
$data = array_intersect_key($object->getData(), array_flip($attributes));
try {
$this->_beforeSaveAttribute($object, $attributes);
if ($object->getId() && !empty($data)) {
$this->getConnection()->update(
$object->getResource()->getMainTable(),
$data,
[$object->getResource()->getIdFieldName() . '= ?' => (int)$object->getId()]
);
$object->addData($data);
}
$this->_afterSaveAttribute($object, $attributes);
$this->getConnection()->commit();
} catch (\Exception $e) {
$this->getConnection()->rollBack();
throw $e;
}
}
return $this;
}