I try to make sql query
$picture = Picture::model()->findBySql('SELECT * FROM tbPictures
LEFT JOIN tbAlbums ON tbPictures.idtbAlbums = tbAlbums.idtbAlbums
LEFT JOIN tbPersons ON tbAlbums.idtbPerson = tbPersons.idtbPerson
WHERE tbPersons.idtbPerson='.$idperson);
the query work good, but I need to get idtbPerson from it.
I write echo $picture->idtbPerson - but i Get an error: "Property "Picture.tbPerson" is not defined"
((( How can I get it
aruna470
(Aruna470)
September 21, 2011, 12:36am
2
Try out after adding $idtbPerson variable to your model class.
alize
(Tocomputerscientist)
July 12, 2013, 2:24pm
3
It is not possible to get related table fields this way unfortunately. The model this way can return only return data for its own fields.
To get the related data you must use the model in the following way:
$picture = Picture::model()->with(‘tbAlbums_relation’)->find(“where clause”)…
sukunj
(Mendparasukunj27)
July 13, 2013, 4:43am
4
nabiullin11:
I try to make sql query
$picture = Picture::model()->findBySql('SELECT * FROM tbPictures
LEFT JOIN tbAlbums ON tbPictures.idtbAlbums = tbAlbums.idtbAlbums
LEFT JOIN tbPersons ON tbAlbums.idtbPerson = tbPersons.idtbPerson
WHERE tbPersons.idtbPerson='.$idperson);
the query work good, but I need to get idtbPerson from it.
I write echo $picture->idtbPerson - but i Get an error: "Property "Picture.tbPerson" is not defined"
((( How can I get it
You can not directly use echo $picture->idtbPerson . you need foreach loop for that
foreach($picture as $data)
{
echo $data['idtbPerson'];
}
otherwise
Use FindAll() instead of findBySql() and after this query…you can retrieve data using foreach loop…
foreach($picture as $data)
{
echo $data['idtbPerson'];
}