在使用从Zend_Db_Table_Row_Abstract继承的类时,如何在Zend中加入表? [英] How can I join tables in Zend while using a class that inherits from Zend_Db_Table_Row_Abstract?
问题描述
我有一个扩展Zend_Db_Table的类,我们称它为'Users',它使用类'User'(从Zend_Db_Table_Row_Abstract继承)作为其rowClass.我需要这种方式,因为用户还有其他使用的方法.
I have a class that extends Zend_Db_Table lets call it 'Users' that uses the class 'User' (inheriting from Zend_Db_Table_Row_Abstract) as its rowClass. I need it this way because User has additional methods that I use.
据我所知,不可能在Users类中联接表,所以我使用:
As far as I know it is not possible to join tables inside my Users class so I use:
$ query = $ db-> select(); $ query-> from(...); $ query-> joinInner(...);
$query = $db->select(); $query->from(...); $query->joinInner(...);
代替
$ this-> select(); ...
$this->select(); ...
但是,当然,我得到的行不是User类的.因此,我想知道如何强制查询返回User对象而不是Row对象.
But then of course the rows I get are not of the User class. So I would like to know how can I force my query to return User objects instead of Row objects.
另一种方法是获取Zend_Db_Table进行连接,在这种情况下,我也将获得所需的内容.
Another way would be to get Zend_Db_Table to make that join in which case I would also get what I want.
推荐答案
在链接重复项中引用David Caunt的答案:
Quoting David Caunt's answer in linked duplicate:
由于Zend_Db_Table提供了行网关功能,如果您加入其他表则行网关功能不起作用,因此必须声明您愿意放弃它.只需拨打
setIntegrityCheck
,它就会起作用:
$select->setIntegrityCheck(false);
这篇关于在使用从Zend_Db_Table_Row_Abstract继承的类时,如何在Zend中加入表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!