Zend framework zend框架子查询

Zend framework zend框架子查询,zend-framework,zend-db-table,Zend Framework,Zend Db Table,我正在使用zend framework 1.12。我要运行以下查询 "SELECT name,(select count(*) from org_quote_template_items where org_quote_template_items.quote_template_id = org_quote_templates.`id` ) as total_line_item FROM `org_quote_templates`" 在我的模型文件中,我这样创建了它。下面是我的模型文件

我正在使用zend framework 1.12。我要运行以下查询

"SELECT name,(select count(*) from  org_quote_template_items where org_quote_template_items.quote_template_id = org_quote_templates.`id` ) as total_line_item FROM `org_quote_templates`"
在我的模型文件中,我这样创建了它。下面是我的模型文件

    class default_Model_DbTable_QuoteTemplates extends Zend_Db_Table_Abstract
{
    /**
     * Name of the original db table
     *
     * @var string
     */
    protected $_name = 'org_quote_templates';


    public function getAllTemplate($where){
        $select = $this->select();        
        $subquery = " (SELECT COUNT(*) FROM  org_quote_template_items WHERE org_quote_template_items.quote_template_id = org_quote_templates.`id` )";

        $select->from(array($this), array('org_quote_templates.*','total_line_items' => new Zend_Db_Expr($subquery)));

        $select = $select->where('organization_id = ?',$where['org_id']);

        $adapter = new Zend_Paginator_Adapter_DbSelect($select);
        $paginator = new Zend_Paginator($adapter);
        $paginator->setItemCountPerPage(
                Zend_Registry::get('config')->paginator->general);
        pr($adapter);
        exit;
    }
}
我在运行代码时遇到以下错误。 “异常‘Zend_Db_Table_Select_exception’,消息为‘Select query无法与其他表联接’”


请告诉我该怎么做?

我想你必须使用
setIntegrityCheck(false)
来完成这项任务

我认为您必须使用
setIntegrityCheck(false)
来实现这一点

您可以在zend中尝试这种方法

$this->select()
->setIntegrityCheck(false)
->from(array('oqt' => 'org_quote_templates'),array('total_line_item'))
->joinLeft(array('oqti' => 'org_quote_template_items'), 'oqti.quote_template_id = oqt.id', array(count(*) as count))   

你可以在zend试试这种方法

$this->select()
->setIntegrityCheck(false)
->from(array('oqt' => 'org_quote_templates'),array('total_line_item'))
->joinLeft(array('oqti' => 'org_quote_template_items'), 'oqti.quote_template_id = oqt.id', array(count(*) as count))   

您的请求中有一个错误。你应该:

    $select = $this->select ();
    $subquery = "(SELECT COUNT(*) FROM  dtempls WHERE order_id = orders.id)";

    $select->from ($this, array (
        'id',
        'total_line_items' => new Zend_Db_Expr ($subquery)
    ));

您的请求中有一个错误。你应该:

    $select = $this->select ();
    $subquery = "(SELECT COUNT(*) FROM  dtempls WHERE order_id = orders.id)";

    $select->from ($this, array (
        'id',
        'total_line_items' => new Zend_Db_Expr ($subquery)
    ));

我试过了,但还是出错了,子查询导致了一些问题。我在zend框架的select语句中找不到如何使用子查询的答案!!我试过了,但还是出错了,子查询导致了一些问题。我在zend框架的select语句中找不到如何使用子查询的答案!!好的,最后我加入表,但我需要的是,如果可以编写子查询,那么它将是好的。好的,最后我加入表,但是我需要的是,如果可以编写子查询,那么它将是好的。