views:

269

answers:

2

Hello my friends.

I have a fetchRow, that is done like it:

$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));

Done it, I would like to retrieve all the files from the file table, like this:

$files = new Database();
$photos = $files->fetchAll($files->select()->where('id = ?',$data->id));

But it returns two different objects, how can I add it to only one object?

If I do:

$this->view->photos = $photos;
$this->view->data = $data;

It works, but how can I merge the photos inside the data?

Thanks and best regards.

A: 

If your table is a data set of files of different types then you need to control how they are hydrated - ie. what objects are returned from the query. To do this you need to make your own Rowset class for the table and set it as a propert of the Database class (assuming its a Zend_Db_Table).

In this rowset class you would examine the property of the row as its hydrated and then choose which class to use 'Data' or 'Photo'. To keep things consistent you will also need to modify the table class in order to handle hydration of a single record (ie. using a find method).

prodigitalson
No idea how to do it, I'm using the zend db table abstract and I did the relation, I'm able to call the second query by doing $row->findDependentRowset('Fotos');Best regard's.
Rodrigo Ferrari
Can you please update your question with the schema for the tables we are talking about and/or the table and row class names? I didnt know you had a dependent rowset i though everythign was in the same table from the way you worded your question and the class name you provided.
prodigitalson
Thanks, I could solve it, turn all to array, then merged than I turned it to object again.Thanks for your replyes, best regard's.
Rodrigo Ferrari
A: 

try

$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));

$files = new Database();
$photos = $files->fetchAll($files->select()->where('id = ?',$data->id));



array_push( $photos, $data);
streetparade
I tryed but it did not worked, I think that the returned values are objects and zend db table abstract can add new objects values.best regard's
Rodrigo Ferrari
You cant do that because a rowset needs to have its data hydrated... this doesnt happen until you loop through the results (at least it didnt the last time i used Zend_Db in 1.7). In order to do what youve described you would need to manually loop through both of those rowsets and assign them to an array, or if all the data has been previously accessed you can call "toArray" on the rowset object and get an array, but this will also turn the row objects into arrays.
prodigitalson
Yes, I do it. Thanks<br>$row = $db->fetchRow($dado)->toArray();<br>$fotos['fotos'] = $db->fetchRow($dado)->findDependentRowset('Fotos')->toArray();<br>$data = (object)array_merge($row,$fotos);Thanks and best regards.
Rodrigo Ferrari