1

The save method of AbstractModel is marked to be deprecated, for this reason I try to avoid using it. Normally I do this by using a repository.

That's fine for things like orders which Magento provides the repository for.

For my own custom types I'm not sure what to do. All examples I've seen of creating a custom repository seem to rely on this deprecated method. The only way I can think to write my own save method would be to use an update db query, but that feels like it defeats the purpose of having an ORM.

In short my question is how do you save custom ORM objects in Magento 2 without using a deprecated method or SQL queries?

Apologies if this is a stupid question. I'm worried I'm missing something as Magento will create getters, setters, factories etc for custom types, but as far as I can tell creating a repository for them is a lot of work.

1 Answer 1

0

Use resource save method. For example


public function save(HamburgerInterface $hamburger)
{
    $hamburger->getResource()->save($hamburger);
    return $hamburger;
}

Check here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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