[eluser]Maglok[/eluser]
I am developing an app that is growing quite big and I am stumbling upon a problem.
The MVC model is easy in concept: You have a Model, View and Controller.
I am just going to sketch a situation here and then ask a few questions about it that have been nagging me as of what is proper to do.
Controllers
- Person
- Event
- Signup
Views
- AddPerson
- EditPerson
- AddEvent
- EditEvent
- AddSignup
- EditSignup
Models
- Person_model
- Event_model
- Signup_model
The model classes would have for example 'add_person', that adds a person to the database. The Person controller would load the model and insert it, no problem there.
If you want the EditPerson view to show a list of Persons you'd load the model in the controller and then pull up get_all, pass that to the view, which displays it.
Now for the confusion. Lets say the models conform to the tables in the database and we have thus a person defined by a person_id, a event defined by a event_id and a signup defined by a signup_id. A signup would in addition be by a person for an event and it would thus contain a person_id and a event_id. Now lets say we want to display a list of the signups for an event and by name of the people participating.
This would require a query that spans all three tables. Tricky. Also it is for displaying purposes, hmm.
Questions
1. If you pull data from more then one table, what model do you put it in? (For 'proper' MVC)
2. If you pull data for display purposes do you pull it in the view or in the controller?
3. If you pull data for display purposes, do you even want a model function or do you just improvise a db query in the view? To me it has always seemed the MVC model means 'do not call the dbase unless it's from a model', so you can easily abstract that and all.
This is just an example, reality is much more complicated.