开发者

Extending Zend_Db_Table_Row_Abstract

开发者 https://www.devze.com 2022-12-20 07:39 出处:网络
I want to extend Zend_Db_Table_Row_Abstract to have some additional fields besides those from table.

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_Mod开发者_StackOverflow社区el_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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号