views:

280

answers:

2

Hi.

I want to extend Zend_Db_Table_Row_Abstract to have some additional fields besides those from table.

Example.

I have

class Automobili_Model_Car extends Zend_Db_Table_Abstract { 
        protected $_name = 'car'; 
        protected $_rowClass = 'Automobili_Model_Row_Car'; 
} 

and

class Automobili_Model_Row_Car extends Zend_Db_Table_Row_Abstract { 
} 

Car table have model_id, which refers to model table (corsa, clio...), I want Automobili_Model_Row_Car to have model loaded from dependent table model, not just model_id from car table.

What is the right weay to do it?

Regards, Sasa Stamenkovic.

A: 

Can you post more detail abouthow you want it to work exactly... I mean you can always fetch the dependent or parent rowset with findDependentRowset and findParentRow respectively.

prodigitalson
+1  A: 

You have a few options:

You have the findDependentRowset() and findParentRow() methods mentioned before. For those I would say read the documentation: http://framework.zend.com/manual/en/zend.db.table.relationships.html. I've never really gotten the hang of this method so I won't say too much about it.

Another option is Zend_Db_Table_Row_Abstract has an init() function that you can override. You can load the other row from there and every time a Car object is created, it will load the model. This can be expensive though as for every object you have another query to your database. If you load 50 rows in one query you have 50 more queries that will executed when the Car object is created.

Another option is to add a getModel() function to the Car class. This function will lazy load the Model class when requested.

Hope this helps.

smack0007
Good point.I was thinking that too, executing extra query is such a waste. But overriding Zend_Db_Table_Row_Abstract::__get() can be interesting. I can fetch referenced data there only in case I need them. Any tips are welcome.I just need to find right way to fetch data from class extending Zend_Db_Table_Row_Abstract. In classes extending Zend_Db_Table_Abstract I run select() or insert(), but never did anything in Zend_Db_Table_Row_Abstract.Thanks.
umpirsky