Answer the question
In order to leave comments, you need to log in
How to properly store related data in activeRecord Yii2?
For example: let's say I have three related tables.
book, authors, tities (The title of the article of each author, i.e. there are several authors in one book and each has its own article).
The links between them are book->hasMany(authors), authors->hasMany(titles).
When adding a book in the form, all data of the article, authors are indicated.
In the controller, calling model=new Book() ... $model->save() .. ..$model_auth=new Auth() .. ->save()... for each model is not a good idea
.
Is it possible somehow to write the Book model itself to save data to related tables, for example, in the AfteSave () method? Or how is it done? Links, examples please, or hints on how you would do it.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question