0

I have been only for a few days in the Magento universe, starting with Magento 2, and I am currently a bit lost regarding the proper way to read and save entities (Model).

At the very begginning, I found a lot of tutorials where the author was using the load() and save() methods. After reading some documentation, I understood that it is because MG2 use an Active Record Pattern.

Coming from Symfony 2/3, I was a little bit disapointed at the beginning (used to Data Mapped Pattern with repository...). But not for long. But today, I found (thanks to the autocompletion of NetBeans) that the above method are deprecated (and so prone to disapear one day or the other...). After a quick search on Google, it seems that now MG2 is going to use more and more a repository pattern. OK that's cool.

But now, I was not able to found any proper tutorial to guide me to create a repository for a custom model. So I decided to look in the build-in module, opening some repos, and what did I found? Still those load() and save() methods.

I assume that's simply legacy code, but I am quite lost now. Does anyone know how to read and write custom entities in MG2?

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
enrico69
  • 515
  • 6
  • 19
  • You can look for inspiration in the catalog module to find repositories, but that can look scary at a first glance. Here is a simple CRUD module I've put together that uses repositories instead of save and load methods – Marius Jul 19 '16 at 15:26
  • Thank you Marius. It is, as you said, "scary", with so much things. But thanks to your work I understand the basics. – enrico69 Jul 23 '16 at 15:36

0 Answers0