Is it possible with Gii to generate a CRUD from DB tables with relationships?
Example tables:
author
id name // имя автора book
id title // название книги author_id // id автора из таблицы author SQL
CREATE TABLE author ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL ) ENGINE = InnoDB; CREATE TABLE book ( id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, author_id SMALLINT UNSIGNED NOT NULL, CONSTRAINT `fk_book_author` FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE ON UPDATE RESTRICT ) ENGINE = InnoDB; Gii generates a method in the Author model; getBooks () method
public function getBooks() { return $this->hasMany(Book::className(), ['author_id' => 'id']); } I understand correctly that with the help of this method you can display the author’s book in view? (if not, you can link to the example)
And the second question: How to create a CRUD from this structure of the database tables in YII2 so that when adding a book you can choose author_id instead of author_id. I mean automated methods (if such exist) so that he from the relation understands that it is necessary to generate a model and CRUD based on the relations.