I know that in php it is good practice to have database tables in a class. In this way,
$myTable = new DbTable_Users(); $res = $myTable->doQuery(); . . $res->getID(); $res->getNAME();
but if I see the result set, maybe JOIN, so mixed fields. A class cannot extend 2 classes. Then how to avoid this?
$res = Factory::doQuery ('SELECT * FROM A LEFT JOIN B ON A.ID = B.ID'); // A fields => ID, FIELD1, FIELD2 // B fields => ID, DATE, FIELD2 $res->getID(); - **now which field?? A.ID or B.ID** ??
There are various design methods for the so-called composite models (where some fields may be associated with other tables).
The most clear way, as for me, is to design database tables / cards as classes of one type, but domain models as classes of another type; the latter would use the former as building blocks.
, :
DbTable_Users User. (, ). Users () . , array($user1, $user2, $user3) .
DbTable_Users
User
Users
array($user1, $user2, $user3)
, Post , . , . - :
Post
SELECT * FROM users INNER JOIN posts ON users.id = posts.user_id WHERE users.id = 1;
User Post , . $user->posts.
$user->posts