M
M
Mark2018-03-18 13:31:30
Yii
Mark, 2018-03-18 13:31:30

How to do competently CRUD for two tables of related tables, if there is a possibility of missing data in the second one?

There are 2 tables: Service
table Responsible for storing services. Fields: id, name, cost, price, min, max. service_api table Some services may have API settings, some may not (handled manually). Fields: service_id(&service=>id), order_link, check_link The question is how to properly display and edit data for these two tables, provided that: Not every service has its own API settings, but each API settings has its own service . At the moment, I have a problem specifically with creating and saving, that is, how to implement it without JS.

In terms of saving, there is an idea: to make a ServiceForm form, which will have the properties of both the Service and ServiceApi tables.
And if, when creating services, the user did not fill in the fields of the service_api table, namely: order_link, check_link - check this and pull the method that will save only data to the service table. But then the question is when editing: how to display data on the form? You can, of course, make a check on the Controller'e whether the service has API settings and if not, display one form, if there is another. But this method seems too cumbersome and not the most correct.
Perhaps there is a more elegant solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-03-21
@webinar

Some services may have API settings

Do you need a separate table for this? Wouldn't it be easier to store this as json in the service table in the "api" column?
What's with the controller? You must have a link in the model. And if it returned null, then there is no associated data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question