D
D
Dmitry2017-03-20 20:43:15
Yii
Dmitry, 2017-03-20 20:43:15

How to properly separate AR and business logic for entities in Yii2?

There is a project on Yii2 and it was decided to separate AR models and logic for them.
I thought to allocate the data storage logic to the repository, but, as I understand it, AR itself implements this pattern.
Now I have the following structure in mind:
app\models\ActiveRecord\Base\BaseFoo - here I store the main class of the model, which is inherited from yii\db\ActiveRecord , at the moment the content is the following: tableName(), validation rules, scripts,
app attribute labels \models\ActiveRecord\Foo - inherit from BaseFoo , behaviors() description if necessary, and logic description here.
Is this structure acceptable? You can, of course, move the Foo model to app\models\Logicor something like that, but I think it's better to store it in app\models\ActiveRecord .
I would be grateful for any alternatives, your own approach in describing the structure of the application is interesting.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2017-03-20
@another_dream

Repository - contains an implementation with a storage layer
ActiveRecord - a tool for working with a database
Service - contains business logic
in the context of a multilayer system:
Service
|
Repository
|
ActiveRecord
upstream uses only downstream layer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question