SQLSTATE[23000]:违反完整性约束:1052 列:字段列表中的 'quantite' 不明确

SQLSTATE[23000]: Integrity constraint violation: 1052 Column : 'quantite' in field list is ambiguous

我参考了其他类似我的问题,但我无法弄清楚为什么我的示例中出现错误。

我有一个看起来像这样的方法:

$select = $this->select()->setIntegrityCheck(false)

                            ->from(array('dmas' => $this->_name), array(
                                'id',
                                'is_new',
                            'id_demande',
                            'id_ds',
                            'id_station',
                            'id AS DT_RowId',
                            'quantite',
                            'quantite as quantite_initiale',
                            'quantite_voulue' => new Zend_Db_Expr("quantite - 
                            coalesce(quantite_attribuee, 0)"),
                            'quantite_attribuee',
                            'is_attribue',
                            'num_station',
                            'id_catalog'
                            ))

                        ->joinLeft(array('cal' => 'catalog_accessory_list'), 
                        'cal.id = dmas.id_catalog', array('id_function1 as id_function_1', 
                        'id_function2 as id_function_2', 'id_function3 as id_function_3'))
                        ->joinLeft(array('cam' => 'catalog_accessory_model'), 'cam.id = cal.id_model', array('name as nom_model', 'id as id_model'))
                        ->joinLeft(array('caf1' => 'catalog_accessory_function1'), 'caf1.id = cal.id_function1', array('name as name_function_1'))
                        ->joinLeft(array('caf2' => 'catalog_accessory_function2'), 'caf2.id = cal.id_function2', array('name as name_function_2'))
                        ->joinLeft(array('caf3' => 'catalog_accessory_function3'), 'caf3.id = cal.id_function3', array('name as name_function_3',
                                'full_designation' => new Zend_Db_Expr("CONCAT_WS(' | ', cam.name, caf1.name, caf2.name, caf3.name)")))

                        ->joinLeft(array('ds' => 'demande_station'), 'ds.id = dmas.id_ds', array('date_disponibilite' => new Zend_Db_Expr("DATE_FORMAT(ds.disponibilite,'%d/%m/%Y')"),'disponibilite' => new Zend_Db_Expr("DATE_FORMAT(ds.disponibilite,'%d/%m/%Y')"),'date_debut_chantier' => new Zend_Db_Expr("DATE_FORMAT(ds.debut_chantier,'%d/%m/%Y')"),'date_fin_chantier' => new Zend_Db_Expr("DATE_FORMAT(ds.fin_chantier,'%d/%m/%Y')")));

以上查询完美运行。但是,当我尝试添加此 joinLeft 时出现错误:

->joinLeft(array('a' => 'accessoire'), 'a.id_catalog = dmas.id_catalog', array('id as DT_RowId','nom as code', 'a.quantite as quantite_stock'))
        ->where('(CAST(dmas.quantite AS SIGNED) - CAST(ifnull(dmas.quantite_attribuee, 0) AS SIGNED)) > 0 '
                . 'AND dmas.quantite > 0 AND (dmas.is_attribue <> 1 OR dmas.is_attribue is NULL) '
                . 'AND ds.accessoire_valid = 0'
                );

错误:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column : 'quantite' in field list is ambiguous

在我看来你需要明确限定这个:a.quantitedmas.quantite。您引入的具有相同列名的 table 现在已经破坏了 dmas 别名的隐式限定能力。