将查询转换为使用 Zend_Db_Select
我在将此查询转换为使用 ZF 的 Zend_Db_Select
时遇到一些问题:(
SELECT b.id, b.title, b.description
FROM memberships AS m
JOIN blogs AS b ON b.id = m.blog_id
WHERE m.user_id = ?
ORDER BY m.created
LIMIT 0, 30
此查询有效并返回结果)
Memberships
是 博客
之间的链接表和用户
。 这是一个简单的 | 编号 | 博客 ID | user_id |
事务。
这是我到目前为止所得到的:
// $table = Zend_Db_Table instance, $id = a user id
$select = $table->select()
->from(array('m' => 'memberships'), array('b.id', 'b.title', 'b.description'))
->join(array('b' => 'blogs'), 'b.id = m.blog_id')
->where('m.user_id = ?', (int) $id)
->order('m.created DESC')
->limit(0, 30);
这是我收到的(对我来说很奇怪)错误:
#0:选择查询无法与另一个表连接
发生在
D:\...\library\Zend\Db\Table\Select.php
的第 211 行。
感谢您的帮助。
I'm having some problems translating this query to use ZF's Zend_Db_Select
:
SELECT b.id, b.title, b.description
FROM memberships AS m
JOIN blogs AS b ON b.id = m.blog_id
WHERE m.user_id = ?
ORDER BY m.created
LIMIT 0, 30
(this query works and returns results)
Memberships
is a link table between blogs
and users
. It's a simple | id | blog_id | user_id |
affair.
Here's what I have so far:
// $table = Zend_Db_Table instance, $id = a user id
$select = $table->select()
->from(array('m' => 'memberships'), array('b.id', 'b.title', 'b.description'))
->join(array('b' => 'blogs'), 'b.id = m.blog_id')
->where('m.user_id = ?', (int) $id)
->order('m.created DESC')
->limit(0, 30);
This is the (strange (to me)) error I'm getting:
#0: Select query cannot join with another table
Occurred on line 211 of
D:\...\library\Zend\Db\Table\Select.php
.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以通过添加 setIntegrityCheck(false) 来使用传统的 $model->select() 对象,如下所示。
这将禁用引发异常的检查:
You could also still use the traditional $model->select() object by adding setIntegrityCheck(false), like so.
This disables the check that is throwing the exception:
当从表对象中检索时,该语句将仅限于我认为的该表。
Zend_Db_Table::select()
方法返回一个Zend_Db_Table_Select
对象,该对象是Zend_Db_Select
的子类并施加此限制。 试试这个:如果您愿意,以下内容应该是等效的:
When retrieved from your table object, the statement will be limited to that table I think. The
Zend_Db_Table::select()
methods returns aZend_Db_Table_Select
object which is a subclass ofZend_Db_Select
and imposes this restriction. Try this instead:If you prefer, the following should be equivalent: