11

What are the differences between a Model and a Resource model? Also what is a model and a resource model?

2 Answers 2

22

Models : Models are where your main business logic should be handled and is a single instance of an object. The model will use the resource model to talk to the database and get/set data for it on save() and load().

Resource Model : A resource model is where your main C.R.U.D happens (Create, Read, Update and delete). The resource model shouldn’t contain business logic however it will talk to the adapters and basically talk to the database.

2
  • Now, repositories should be used instead of the resourceModel class right? Nov 13, 2018 at 8:21
  • 3
    I have explain answer as per question Nov 13, 2018 at 14:43
0

Model

Models are where your main business logic should be handled and we can get or set one row of entity by using Model. Model will call the resource model to get or set entity in database.

Resource Model

CRUD operations are handled in resource model but it don't have a business logic.

Collections

Collection have lot of attributes and filters. It has a whole entity of data. Using filter method, we can filter specified data from database table.

Your Answer

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

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