Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a module and I have a collection model class(under Model/Mysql4/MyModule/Collection.php), resource class (Model/Mysql4/MyModule.php), abstract model class (Model/MyModule.php) and a setup class (Model/Resource/Mysql4/Setup.php).

I really created them and my module worked perfectly. But I really don't know exact differences between all those models.

I really don't know which function should I put to which file. In a dummy example, I have a function to get all categories with 3 products inside. Where should I define my function and in which model ?

share|improve this question
possible duplicate of Why magento use resource and mysql4 model collection? – Fabian Blechschmidt Jul 17 '14 at 7:34
Thanks @FabianBlechschmidt You are somehow correct. I really know the overal differences , but currently I really don't know where to put my function? I confused with all these...What do you suggest ? Thanks for your comment and answer on that question. It was helpful. – Michel Gokan Jul 17 '14 at 7:36
well, have a file like (Model/Mymodel.php) and make it extend your abstract model. Then, define some functions there. – Julien Lachal Jul 17 '14 at 7:37
@JulienLachal Thanks for your suggestion, but why there ? I mean why not in collection model ? What will happen if I put it to wrong file ? How can I know my function related to which file here ? Thanks again. – Michel Gokan Jul 17 '14 at 7:38
up vote 2 down vote accepted
  • Resource collections are a list of models, everything which filters the collection, orders it or joins stuff into it belongs here.
  • resource models are the ORM (more or less), so everything which communicates with the database belongs here. getItemById(), createNewItem(), etc.
  • Model is a data container and the business logic so everything else belongs here.

But depending on the complexity of the business logic I would think about creating more models (without any extend) and helper (when the logic doesn't change any inner status)

share|improve this answer
That's whay I wanted to know. You are the man :) – Michel Gokan Jul 17 '14 at 7:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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