M
M
maximilianoarturo2016-02-18 15:12:24
Yii
maximilianoarturo, 2016-02-18 15:12:24

Adding related data to 2 tables Yii2. How to implement?

There are 3 tables:
user
id | username
books_categories
id | category_name
user_books
id | user_id | category_id | book_name
When adding a value to the User model, it is also necessary to fill in UserBooks.
In the view, I display something like this (let's say that you always need to add 2 books):

<input type="text" name="User[username]" />
<input type="text" name="User[book_name][1]" />
<input type="text" name="User[book_name][2]" />

where 1 and 2 are id from books_categories
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jacksparrow, 2016-02-18
@jacksparrow

Through a link. And generally it is simple in transaction. In case you didn't, write the connections in the models.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question