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
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.