I have two variants adding data using Model. Which variant is more rignt ?

Especially I want to ask about this $slider->setDataChanges(true);in first variant because I must set up _hasDataChanges = true if I want to save data.

1.Variant enter image description here


enter image description here


As per Magento standard, the second option is right to add a new record to an entity using the repository.

If you want to update exist then you have to load the record by a primary key using getById()

$slider = $this->sliderRepository->getById('PKID');

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.