Is there any way to create a virtual model join table and then just call $direps = $this->VirtualTableModel-> find() instead of writing join function in controller?
Basically you can define the association between 2 tables inside the src/Model/Table/PeopleTable.php and then reuse that associations wherever you like.
In your example you first need to add a hasMany() association between people and direps_rulings
If you then add a similar association in your direps_rulings Table Class between your direps_rulings and ruling table you can then use that as well via
And to answer your question: Usually in a MVC framework one goes by the rule āfat models, skinny controllersā.
But model code should not contain ābusiness logicā, this should still be in the controller (or if its too much in a separate service/utility class)
To be fair this topic is very opinionated because this is more about software design and how you structure your code. Both ways work and either one has its advantages and disadvantages.
As I āgrew upā with the 3-tier architecture, I always/still have trouble where to put the business logic in MVC, so Iām always triggered when reading about this topic.
In my mind joins are definitely āmodelā, so Iām glad thatās not giving me a problem. Moreover, because I ābakeā, joins get in the model by default.
Thank you very much KevinPfeifer. Your example is exactly what I was searching for. I like the āfat models, skinny controllersā. One have to say that these credos usually rely on deep experience of people, who creted them. They must have sense and justification.