Magento 2 - Difference between Model, ResourceModel. Collection and RepositoryWhat is the difference between $model->getOrigData(); and $model->getData();?<Namespace>_<module>_Model_<module>::_construct() not allowing method callsExample of Code and Configuration Needed for a Simple Magento 2 CRUD Model?Best Way to Load a Custom Model in Magento 2Are collections history in Magento 2?What is the proper way of implementing service contracts in Magento 2?Magento2: Difference between Factory and RepositoryWhat and why is the proper way to load a modelCorrect way to save entries to databaseThe difference in use Repository or RepositoryInterface to load model

"You are your self first supporter", a more proper way to say it

Paid for article while in US on F-1 visa?

Why does Kotter return in Welcome Back Kotter?

Why is consensus so controversial in Britain?

Cross compiling for RPi - error while loading shared libraries

dbcc cleantable batch size explanation

Can a vampire attack twice with their claws using multiattack?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How old can references or sources in a thesis be?

How much of data wrangling is a data scientist's job?

How to regain access to running applications after accidentally zapping X.org?

How much RAM could one put in a typical 80386 setup?

What's that red-plus icon near a text?

Why are electrically insulating heatsinks so rare? Is it just cost?

Why is Minecraft giving an OpenGL error?

Is it legal for company to use my work email to pretend I still work there?

Codimension of non-flat locus

How to determine what difficulty is right for the game?

Is it possible to do 50 km distance without any previous training?

Can a monk's single staff be considered dual wielded, as per the Dual Wielder feat?

Modeling an IP Address

How to move a thin line with the black arrow in Illustrator?

How to source a part of a file

How does one intimidate enemies without having the capacity for violence?



Magento 2 - Difference between Model, ResourceModel. Collection and Repository


What is the difference between $model->getOrigData(); and $model->getData();?<Namespace>_<module>_Model_<module>::_construct() not allowing method callsExample of Code and Configuration Needed for a Simple Magento 2 CRUD Model?Best Way to Load a Custom Model in Magento 2Are collections history in Magento 2?What is the proper way of implementing service contracts in Magento 2?Magento2: Difference between Factory and RepositoryWhat and why is the proper way to load a modelCorrect way to save entries to databaseThe difference in use Repository or RepositoryInterface to load model






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following:



Model



Is the entity class with ONLY getters/setters and magic methods.



ResourceModel



Is the layer responsible of C.R.U.D operations. This class should contains ONLY the _construct method to map my entity with the database table.



Collection



As the name suggested, it's a class that implements IterableInterface and give me only a list of Entity.



Repository



It's a class that expose API methods to the external and it's also used to execute operations to database. It's used to save/load/delete entity (internally I think that for these CRUD operations it should use the ResourceModel) and to expose methods to get collections of results.



EntityNameInterface



It's the interface that Model should implement.



EntityNameRepositoryInterface



It's the interface that Repository should implement.



But not all Magento modules work in this way, so there are modules that don't use this approach yet, but for compatibility reasons they use the old approach. Is it correct what I learned to it?










share|improve this question






























    1















    I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following:



    Model



    Is the entity class with ONLY getters/setters and magic methods.



    ResourceModel



    Is the layer responsible of C.R.U.D operations. This class should contains ONLY the _construct method to map my entity with the database table.



    Collection



    As the name suggested, it's a class that implements IterableInterface and give me only a list of Entity.



    Repository



    It's a class that expose API methods to the external and it's also used to execute operations to database. It's used to save/load/delete entity (internally I think that for these CRUD operations it should use the ResourceModel) and to expose methods to get collections of results.



    EntityNameInterface



    It's the interface that Model should implement.



    EntityNameRepositoryInterface



    It's the interface that Repository should implement.



    But not all Magento modules work in this way, so there are modules that don't use this approach yet, but for compatibility reasons they use the old approach. Is it correct what I learned to it?










    share|improve this question


























      1












      1








      1


      1






      I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following:



      Model



      Is the entity class with ONLY getters/setters and magic methods.



      ResourceModel



      Is the layer responsible of C.R.U.D operations. This class should contains ONLY the _construct method to map my entity with the database table.



      Collection



      As the name suggested, it's a class that implements IterableInterface and give me only a list of Entity.



      Repository



      It's a class that expose API methods to the external and it's also used to execute operations to database. It's used to save/load/delete entity (internally I think that for these CRUD operations it should use the ResourceModel) and to expose methods to get collections of results.



      EntityNameInterface



      It's the interface that Model should implement.



      EntityNameRepositoryInterface



      It's the interface that Repository should implement.



      But not all Magento modules work in this way, so there are modules that don't use this approach yet, but for compatibility reasons they use the old approach. Is it correct what I learned to it?










      share|improve this question
















      I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following:



      Model



      Is the entity class with ONLY getters/setters and magic methods.



      ResourceModel



      Is the layer responsible of C.R.U.D operations. This class should contains ONLY the _construct method to map my entity with the database table.



      Collection



      As the name suggested, it's a class that implements IterableInterface and give me only a list of Entity.



      Repository



      It's a class that expose API methods to the external and it's also used to execute operations to database. It's used to save/load/delete entity (internally I think that for these CRUD operations it should use the ResourceModel) and to expose methods to get collections of results.



      EntityNameInterface



      It's the interface that Model should implement.



      EntityNameRepositoryInterface



      It's the interface that Repository should implement.



      But not all Magento modules work in this way, so there are modules that don't use this approach yet, but for compatibility reasons they use the old approach. Is it correct what I learned to it?







      magento2 model service-contract






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 hours ago







      Mirko Rapisarda

















      asked 6 hours ago









      Mirko RapisardaMirko Rapisarda

      536




      536




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268974%2fmagento-2-difference-between-model-resourcemodel-collection-and-repository%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268974%2fmagento-2-difference-between-model-resourcemodel-collection-and-repository%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

          Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

          Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»