There are two related tables: in the first one there are blog posts, in the second one - pictures for the post.
Pictures can be unlimited.
When creating a post, it is necessary to record the post itself in one table, and the pictures to it in another. How to implement it?
- oneOnly two requests. The problem is that the value of the referencing field for the table of images will be obtained only after fixing the insertion into the table of posts. Those. second INSERT only after the completion of the first INSERT. - Akina
- Here in the code that the gii generator does not insert at all, there through $ model-> save () everything is worked out as I understand it - Dmitry Ivanov
- It seems understood, can you still suggest how to write an array of data? I get the way the images will come in an array. - Dmitry Ivanov
- there through $ model-> save () everything is processed. But SQL queries will still get to the MySQL server. And there should be two to add, yes, plus one more. Can $ model-> save () ensure the execution of the first request to add (the first request to the server), the receipt of the key value generated by auto-increment (the second request!) And the second request to add (the third request!) With the value of the obtained auto-increment substituted - I have no idea ... Of course, it is formally possible to get rid of the intermediate request, but only formally. - Akina
- Either each picture has its own record, which is convenient and logical, or serialize ($ arr_images) before recording, and when selecting unserialize ($ row ['images']) - fedornabilkin
|