A jak powinno wyglądać tworzenie encji dla kolekcji userow . Czy powinienem pobrać tablice danych w jednym zapytaniu joinem i na podstawioe nich stworzyc encje czy tworzyc kilka osobnych zapytań, np.:
1) zapytanie z joinem
class UserRepository
{
//jakies atrybuty i metdody
public function findAll()
{
$aRows = $_usersDAO->findAll(); //zwraca uerow z profilami
foreach($aRows as $row)
{
$aUser = array('id' => $row['id'], 'imie' => $row['imie'],
'nazwisko' => $row['nazwisko'],
'profil_id' => $row['profil_id']
);
$oUserEntity = new UserEntity($aUser);
$aProfil = array('id' => $row['profil_id'], 'telefon' => $row['telefon'],
'email' => $row['email']
);
$oUserEntity->addProfil(new ProfilEntity($aProfil));
$aContener[] = $oUserEntity;
}
return new UserCollection($aContener);
}
}
2) zwykly select
class UserRepository
{
//jakies atrybuty i metdody
public function findAll()
{
$aRows = $this->_usersDAO->findAll(); //zwraca userow
foreach($aRows as $row)
{
$aUser = array('id' => $row['id'], 'imie' => $row['imie'],
'nazwisko' => $row['nazwisko'],
'profil_id' => $row['profil_id']
);
$oUserEntity = new UserEntity($aUser);
$oProfilEntity = $this->_oProfilRepository->find($row['profil_id'])
$oUserEntity->addProfil($oProfilEntity);
$aContener[] = $oUserEntity;
}
return new UserCollection($aContener);
}
}
class ProfilRepository
{
//jakies atrybuty i metody
public function find($id)
{
$aRow = $this->_oProfilDao->find($id);
return new ProfilEntity($aRow);
}
}
3) tworze kolekcje userow bez pobierania profilu i dopiero w widoku gdy wyswietlam userow wywoluje metdoe (z pierwszego postu) getProfil, ktora zwroci mi obiekt Profil.
4) jakieś inne rozwiązanie?