Let's say I have two models:
class Book
{
public $book_id;
public $book_author_id;
public $title;
}
class Author
{
public $author_id;
public $author_name;
}
I'm used to writing something like this:
$DB->query("SELECT book_id, title, author_name
FROM book
LEFT JOIN author
ON book_author_id = author_id
");
Suppose I am not interested in the individual queries for this association. How can I continue? Here are some things I've heard:
- create MySQL VIEW UNION
- create a VIEW model class
The application I'm working on includes dozens of tables and is highly optimized in procedural code (almost no SELECT * anywhere, for example). I am refactoring to make it more maintainable (I am also the creator), but I would like to have the flexibility of using joins when I need, without compromising the structure of my files and database calls.
Perhaps a related question is related to the inclusion of other models:
class Author
{
public $author_id;
public $author_name;
public (array) $authors_books;
}
, -, .