Yii2: Clarify what is M in MVC

Created on 23 Mar 2018  ·  20Comments  ·  Source: yiisoft/yii2

The «Model» is a very unsuitable name for the class Model. Word «model» is associated with a whole layer (many classes) of MVC architecture. Concrete class shouldn't have such name. It's mess, chaos, anarchy... :D

I propose the name «Collector» (collect, load and validate data). ActiveRecords, forms and data filters – they all can be "collectors".

docs

Most helpful comment

No. Model is the exact name it should have. People are used to Model. Please don't start messing things up @samdark

All 20 comments

Word «model» is associated with a whole layer (many classes) of MVC architecture.

It implies to rename "Controller" and "View" classes too?

I think the names are suitable. Maybe changing these class to abstract would be enough.

It implies to rename "Controller" and "View" classes too?

No. Model is a larger (more complex) layer in comparison with Controller/View layers.

I think that "Model" word expresses all complexity related to data manipulation, that reflects effectively his rule in MVC pattern.

Then Collector makes me think of a kind of helper classes to handle collections, or data aggregator, but not something to get and manipulate data from source.

I think it will be too much for 2.1 but we may consider it for 2.2.

There are alternative terms for the same pattern such as http://pmjones.io/adr/

Understood @rugabarbo . I was confused about model meaning.

If it will be changed, I propose something like DomainModel, Entity, DataModel, or ModelObject.
I think it sounds more concrete.

If I had to pickup a new name, I'd vote for Entity, because how @berosoboy said, it has concrete feeling.

Anyway, thanks to @rugabarbo to have opened this discussion.

Are there embedded tools in GitHub to make a survey (such as twitter) ?

Not as I'm aware of. There are surveys at Facebook and in Slack though.

It will be easier to rename the framework to Laravel.
use Illuminate\Database\Eloquent\Model;

Sarcasm!

No. Model is the exact name it should have. People are used to Model. Please don't start messing things up @samdark

@twisted1919 People is used to Model class but «Model» isn't the exact name it should have. Don't mix «correctly» and «habitually».

We have these:

  1. Active Record. Saves data to DB and loads it from DB.
  2. Form. Validates data, performs an action on form submit.
  3. Search. Validates parameters, forms query or criteria from these.
  4. API Resource. Defines how data is serialized, validates filters input, builds query based on filters input.

We have these:

  1. model ActiveRecord. Saves data to DB and loads it from DB. (extends of Model)
  2. model Request - validates data of requests by a scenario. (extends of Model)

I don't want to see in documentation:
We have there:
collector ActiveRecord
collector Request
entity ActiveRecord
dao Form
datamodel PostSearch
model object PostCreateRequest
...

Any way you will use model word when describe objects of requests or activerecords
No need rename Model class

Agreed to leave as is.

Closing the issue at least until we find better reasons to rename Model

We probably need to call these "model object" in the guide and mention that "model" itself consists of many model objects and other classes representing domain layer.

Hey, yo. Why this class should called something about Model? If we looking into code: validations and attributes (and something from base classes). I think it closer to Form or Validation name.

So, can you divide this class to 2 classes - Validation and Form? For example, In Form you have all attributes method. In Validation - validate mehods. What do you think?

All the ideas to change it to something else are plain stupid and without any reason.
We have other pressing matters than changing the model class to something else.
I don't even understand why this issue is still opened.

I don't even understand why this issue is still opened

There are probably thousands of bugs in Yii and of course, they differ in having different priorities. Naming schema issue usually gets a lower priority than logic issues. The priority must control the time of bug fixing. That might be the reason why this issue is still opened.

The problem is that someone, came up and said "Let's rename class Model to something else". Not only that they said 'to something else" meaning they had no clue what they want, but also to me it just sounds like "let's take a piece of perfect fundamental concept of Yii and screw it because i want
to do so, even if i have no reason, or if i do, i don't know it yet".

M in MVC says Model for a good reason, because it handles data modeling, regardles of it's source or destination. The name is perfectly fine people, let's move along and forget this non-sense of renaming a fundamental part of the framework.

Come one, this is going too far by now.

https://github.com/yiisoft/yii2/issues/15964#issuecomment-377775076 is what I see as solution i.e. edit the guide and API docs and replace "model" with "model object" in all guide pages and APIdocs.

Was this page helpful?
0 / 5 - 0 ratings