I cant seem to find any information why we need to create a Collection.php file inside ResourceModel and what is the purpose of collection.

  • The collection model is considered a resource model which allow us to filter and fetch a collection table data. – HIren Kadivar Feb 27 at 4:52

With a model and resource model, you are having everything that you need/want to fetch and save from/into the database.

However, there will be some situation when you’ll require to fetch multiple models of a particular type. To solve this problem, every CRUD model in Magento 2 has a corresponding resource model collection.

A collection collects individual models. It’s considered as a resource model because it builds the SQL code which required to pull the information from a database table.

For more information you can refer this site

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.