views:

48

answers:

2

Is it possible to run an SQL (Zend_Db_Select) query against a Zend_Db_Table_Row object? What about joining two Zend_Db_Table_Row objects?

I know it sounds a bit retarded, but I'm processing hundreds and thousands of rows. I already have the row object that I'm manipulating, so I don't want to query the db again.

I hope that's clear. If not, please ask me to clarify.

Edit:

To clarify, the objects are in memory. I've already retrieved them from the database.

The reason for this is:

There are thousands of records in a "log" table. I need to react to these depending on multiple user defined criterion. Time is important when processing these logs. There for a new process is forked to make this happen in a timely manner. A new process is forked for each log. Hence, the objects already exist in memory.

+1  A: 

Consider defining the relationships and then calling findDependentRowset() on the Row object:

http://framework.zend.com/manual/en/zend.db.table.relationships.html

Tim
I already have the objects in memory. Will I be able to do a query against them?
sims
Assuming you can define the relationships in your Zend_Db_Table classes and get them back into memory, yup.
Tim
And how would I do that? $rowobj->fetchRow($select); ?
sims
A: 

The Zend_Db_Table_Row objects you have are rows, they cannot be queried as they are no longer in the database, they are in memory as part of the ZF. They are a set of data in memory handled by PHP - they no longer have anything to do with the database so they cannot be queried as you are suggesting.

You should use findDependentRowset() in your models or Zend_Db_Table class to define the relationships between tables, ZF will then write join statements for you to JOIN tables together, the joined data will then be in your Zend_Db_Table_Row objects after you query the datbase.

Or you can use join() as detailed here to JOIN two or more tables together. You need to do the joins on the select object you are querying. You need to use the power of the database engine to get the data you need. Doing this in PHP is much much slower then using the datbase.

jakenoble
That's the answer I was looking for. You cannot query a Zend_Db_Table_Row object. I thought there might be some dandy Zend mechanism for doing this from looking at the Zend_Db_Table_Row object. I guess that was wishful thinking. The object is already in memory. I'm not going to query the database again.I already gone ahead with the convoluted if structure. It's not too bad - 5 if statements.
sims