For example:
Query
SELECT book.\*,author.* FROM book
INNER JOIN author ON author.id = book.author_id
WHERE book.id=1
Get model
$modelBook = Book::find()->innerJoin('author','author.id = book.author_id')->where(['book.id'=>1])->one();
$modelAuthor = Author::findOne(['id'=>$modelBook->author_id]);
The problem:
How can I get 2 activerecord model Book
and Author
with just only one mysql execute?
I know that we can use with()
function, but it spend another query SELECT ...IN(...)
to get second model, although we have sufficient data from join query
Is there a more effective solution ?