Where to put custom model function
-
11-12-2019 - |
Pergunta
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 ?
Solução
- 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)