扩展 Zend_Db_Table_Row_Abstract
我想扩展 Zend_Db_Table_Row_Abstract 除了表中的字段之外还有一些附加字段。
例子。
我有
class Automobili_Model_Car extends Zend_Db_Table_Abstract {
protected $_name = 'car';
protected $_rowClass = 'Automobili_Model_Row_Car';
}
Car
class Automobili_Model_Row_Car extends Zend_Db_Table_Row_Abstract {
}
表有 model_id,它指的是模型表(corsa、clio...),我希望 Automobili_Model_Row_Car 从依赖表模型加载模型,而不仅仅是从汽车表加载 model_id。
正确的做法是什么?
问候, 萨萨·斯塔门科维奇
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有几个选择:
您有前面提到的 findDependentRowset() 和 findParentRow() 方法。对于那些我想说阅读文档: http://framework .zend.com/manual/en/zend.db.table.relationships.html。我从来没有真正掌握这个方法,所以我不会说太多。
另一个选项是 Zend_Db_Table_Row_Abstract 有一个可以覆盖的 init() 函数。您可以从那里加载另一行,每次创建 Car 对象时,它都会加载模型。尽管对于每个对象,您都需要对数据库进行另一个查询,但这可能会很昂贵。如果您在一个查询中加载 50 行,则在创建 Car 对象时将执行另外 50 个查询。
另一种选择是向 Car 类添加 getModel() 函数。该函数将在请求时延迟加载模型类。
希望这有帮助。
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.
您能否发布有关您希望它如何准确工作的更多详细信息...我的意思是您始终可以分别使用
findDependentRowset
和findParentRow
获取依赖行集或父行集。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
andfindParentRow
respectively.