D
D
Dmitry Kim2016-03-25 11:42:25
Yii
Dmitry Kim, 2016-03-25 11:42:25

What is the best way to associate contact details with a YII2 model?

There is a catalog of organizations, a catalog of vacancies, a catalog of announcements. Each entity from these tables can have several contact data both by type and quantity. There is also a contact data table, a one-to-many relationship. The contact data table will contain the following fields:

id - primary key
content_type - тип связанного контента
content_id - id связанного контента
contact_type - тип контактных данных
contact_title - название контактных данных
contact_data - непосредственно контактные данные
contact_description - описание контактных данных

For example:
catalog | 004 | phone | Александр | 8 555 333 222 | администратор
market | 543 | address | - | ул. Ленина, 52 | магазин оптовой продажи
vacancies | 010 | email | Оптовые продажи | [email protected] | -
catalog | 005| url | - | magazin.domain | -

When saving the main model - just insert the address data into the contact data table. Deletion is the same. And what is the best thing to do when editing a model: delete all contact data from the table and insert new ones, or somehow look for changed data? I am also interested in the way to send contact data from the form: should the contact data fields have the same model name (for this you need to add additional fields to the main model) or their own?
I'm sure everyone has already implemented such functionality using both options. How is it better and easier in the end?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-03-25
@webinar

www.yiiframework.com/doc-2.0/guide-db-active-recor...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question