按引用列对 Zend_Db_Table 行集进行排序
进行连接选择
我知道我可以通过 _referenceMap 定义关系,我知道我可以通过$db->select()
,但我需要的是在扩展 Zend_Db_Table_Abstract 的模型中获取行集> 然后根据另一个表中引用列的值对其进行排序。
有一些解决方法可以做到这一点吗?
编辑:
这是示例:
第一个表:
表格bug列id、bugname、authorid
第二个表:
表格作者列id,作者姓名
我有一个模型Model_Bugs扩展了Zend_Db_Table_Abstract
我想做这样的事情:
< code>$model->fetchAll($model->select()->order('authorname ASC'))
这意味着,我需要连接表并按列排序,即不在模型表中。
感谢您的帮助,
简
i know i can define relationships through _referenceMap, i know that i con join selects trough
$db->select()
But what i need is to fetch rowset in model extending Zend_Db_Table_Abstract
and then order it by value of referenced column from another table.
Is there some workaround to do that?
edit:
heres is the example:
first table:
table bugs columns id, bugname, authorid
second table:
table authors columns id, authorname
I have a model Model_Bugs extends Zend_Db_Table_Abstract
I want to make something like this:
$model->fetchAll($model->select()->order('authorname ASC'))
This means, that i need to join tables and sort by a column, which is not in the model table.
thanks for help
Jan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在
Model_Bugs
中添加一个方法,如下所示:但是要做到这一点,您必须关闭 ZF 的表完整性检查(上面的
setIntegrityCheck(false)
),这意味着您不会'无法直接对结果行调用save()
。但如果它用于只读目的,它就可以工作。如果您需要将行集保存回数据库,您可能必须首先按照您想要的顺序从
Model_Authors
选择作者 ID,然后重新排序您的Model_Bugs
相应地查询。虽然比较混乱,但它可以工作。I would add a method in
Model_Bugs
like so:But to do this you have to turn off ZF's table integrity checking (
setIntegrityCheck(false)
above), which means you won't be able to directly callsave()
on the resulting rows. But if it's for a read-only purpose, it will work.If you needed to save rowsets back to the database, you may have to first select the author ID's from
Model_Authors
in the order you want them, and then re-order yourModel_Bugs
query accordingly. It's messier but it can work.