C
C
CoolerMan2014-03-08 10:19:03
MySQL
CoolerMan, 2014-03-08 10:19:03

MVC Yii implementation (model links, cascading delete)?

Does the MVC implementation imply processing only one selected record?
The approach in Yii does not make me very happy with AR, in order to delete a record, you first need to call it, and then do something with it.
Relations of the Yii rule is also a strange connection of models, where for one record I cannot connect join, I will have to perform 150 MVC connections (figuratively).
The very idea of ​​MVC attracted me by the separation of logic and presentation of information, in this situation I don’t need a bicycle, I would like to be able to solve these issues:
1) how to implement deletion, calling and processing of an array of data, and not to loop on repetition with each entry;
2) as well as linking data from different tables.
The idea is to move this into a separate model (Service Layer), in which you can collect the processing of a large number of records and immediately implement the connection between tables, possibly join sets and other things.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2014-03-08
@CoolerMan

Judging by your question, you misunderstand the idea of ​​MVC or confuse MVC and ORM.
MVC doesn't prescribe anything about how you work with data. This pattern only implies the separation of your business logic (data and data processing) and presentation through an intermediate layer of controllers.
How data is stored is weakly related to business logic, it is usually taken out to the service layer. And the same yii does not limit you in anything. You can choose not to use ar at all, you can replace it with a data mapper (using doctrine). Let's say your data should not know anything at all about how it is stored, even controllers should not really be aware of this. Usually, for this, an intermediate layer is introduced that works with data and encapsulates all the logic for saving / deleting records. This reduces the coupling of the system and reduces the cost of further application support.
ps Read about DDD, SOLID principles

C
CoolerMan, 2014-03-08
@CoolerMan

In short, as I understand it, we have to work with one table:
delete All
update All
Save
Insert
Find all
Eager loading from relations
With is possible.
Other methods
of Bulk insert, delete, update we use CDbCriteria

P
p4s8x, 2014-03-08
@p4s8x

Removing related data is perfectly solved - using CASCADE in the DB.
For bulk deletes/updates, there are UpdateAll DeleteAll and similar AR methods.

C
CoolerMan, 2014-03-08
@CoolerMan

Updating, deleting in different tables is implied.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question