I am trying to create a PHP application using the MVC pattern. I am new to MVC and I do not use a framework since I want to understand in more depth the underlying MVC processes.I have a question regarding models, JSON representation and foreign keys. Lets assume that I have two models:
Class User {
public $id;
public $name;
public $gender_id;
}
Class Gender{
public $id;
public $description
}
The User->gender_id is a foreign key to Genders->id table.
My URI is /users/1 which is supposed to return the following JSON:
{"id":1,"name":"john","gender":"male"}
Is the controller's duty to know the model relations and retrieve the necessary data (user & gender model) which will then be passed to a view that will output the JSON ? Or should the association be defined somehow in the User's model? The gender description is a descriptive attribute but somehow it must be included in the Users view.
Regards