F
F
Freud's cat2019-01-27 20:32:26
Design patterns
Freud's cat, 2019-01-27 20:32:26

Why do I need a model if I'm using an ORM?

Subject. I am new to mvc. I connected an ORM-ku in the model, I call its methods in the controller. Why else would I need a model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mysterion, 2019-01-27
@medbrat69

From WIKI:

The model provides data and methods for working with them: queries to the database, checking for correctness. The model does not depend on the view (does not know how to render data) and the controller (does not have user interaction points) simply providing access to the data and managing it.
The model is built in such a way as to respond to requests by changing its state, and the notification of "observers" can be built in.
The model, due to independence from the visual representation, can have several different representations for one "model".

Simply put, the model is an intermediary between the controller and the database. And in your case it should be between the controller and ORM.
This will allow the logic of obtaining, entering, deleting and changing data in the database into the model. Including all sorts of validators, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question