Magento深入理解-Grid报错clause is ambiguous问题
我记得之前没少讲过Grid,今天在写Grid遇到这样一个错误,将解决办法分享下。
SQLSTATE[ 23000 ] : Integrity constraint violation: 1052 Column 'increment_id' in where clause is ambiguous
这个错误怎么来的呢,关键是clause is ambiguous。
使用Grid必须要设置一个Collection,往往这个Grid需要联表查询,就是写join语句。请看下面例子:
protected function _getCollectionClass( )
{
return 'sales/order_shipment_grid_collection' ;
}
protected function _prepareCollection( )
{
$collection = G:: getResourceModel ( $this -> _getCollectionClass( ) ) ;
$collection -> getSelect ( )
-> joinLeft ( array ( 'o' => 'sales_flat_order' ) , 'main_table.order_id = o.entity_id' , 'grand_total' )
-> joinLeft ( array ( 'st' => 'sales_flat_shipment_track' ) , 'main_table.order_id = st.order_id' , array ( 'carrier_code' , 'number' , 'shipped_time' ) ) ;
$this -> setCollection ( $collection ) ;
return parent:: _prepareCollection( ) ;
}
这段例子是我改写后台配送模块时用到的。原来只是一个简单的表,因为需要跟COD结算、还要监督发货部门的效率。所以需要将订单金额、发货时间等等 联表查询出来,问题出在shipment表有个increment_id字段,而关联的order表同样也有这个increment_id字段。
按下面的这样来配置Grid:
$this -> addColumn ( 'increment_id' , array (
'header' => G:: helper ( 'sales' ) -> __( 'Shipment #' ) ,
'index' => 'increment_id' ,
'type' => 'text' ,
) ) ;
本来我们这里的increment id是物流号,而订单里的increment id是订单号,打开页面,Grid可以正常显示,但是当尝试搜索物流号的时候就会报错了,就是上面的错误。
于是开始找哇,几乎看遍了后台所有的grid,就不信找不到,终于出现了这样一段代码:
$this -> addColumn ( 'created_at' , array (
'header' => G:: helper ( 'reports' ) -> __( 'Created At' ) ,
'width' => '170px' ,
'type' => 'datetime' ,
'index' => 'created_at' ,
'filter_index' => 'main_table.created_at' ,
'sortable' => false
) ) ;
$this -> addColumn ( 'updated_at' , array (
'header' => G:: helper ( 'reports' ) -> __( 'Updated At' ) ,
'width' => '170px' ,
'type' => 'datetime' ,
'index' => 'updated_at' ,
'filter_index' => 'main_table.updated_at' ,
'sortable' => false
) ) ;
请看G_Adminhtml_Block_Report_Shopcart_Abandoned_Grid这个文件。
原来Column可以设置filter_index,之前自己还尝试’index’=>’main_table.increament_id’等等,原来这样就可了,于是上面我改的代码变成了这样:
$this -> addColumn ( 'increment_id' , array (
'header' => G:: helper ( 'sales' ) -> __( 'Shipment #' ) ,
'index' => 'increment_id' ,
'filter_index' => 'main_table.increment_id' ,
'type' => 'text' ,
) ) ;
爽~~过滤正常了~~ :)
相关推荐
1000BASE-X IEEE 802.3-2008 Clause 36 - Physical Coding Sublayer (PCS)_latest.tar.gz
Clause37 GE自协商原理,自协商状态图详细讲解; • Location in the OSI Stack • Interface to the PCS • Auto-Negotiation functionality
1000BASE-X-AN-Clause37-V1.0.doc
1000BASE-X-PCS-Clause36-V1.0.doc
The degree of a table is the number of _____ in the table. (a) keys (b) columns (c) rows (d) foreign keys Correct answer is (b) Your score on this question is: 10.00 Feedback: (b) ...
jslicense-bsd-2-clause 格式的两条款(“简化”)BSD 许可证
1、AVG([DISTINCT|ALL] expr) OVER(analytic_clause) 计算平均值。 例如: --聚合函数 SELECT col, AVG(value) FROM tmp1 GROUP BY col ORDER BY col; --分析函数 SELECT col, AVG(value) OVER(PARTITION BY col ...
资源分类:Python库 所属语言:Python 资源全名:clause-1.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Q485882 - TcxPivotGridChartConnection - Row totals are included to the sdAllShown source data if the pivot grid's OptionsView.RowTotalsLocation property is set to rtlTree ExpressQuantumGrid Suite Q...
Q485882 - TcxPivotGridChartConnection - Row totals are included to the sdAllShown source data if the pivot grid's OptionsView.RowTotalsLocation property is set to rtlTree ExpressQuantumGrid Suite Q...
Q435475 - Tabular and Layout Views - The View does not synchronize edit value changes with the data controller in the OnEditChanged ...and a grid item's Properties.ImmediatePost property is set to True...
Q435475 - Tabular and Layout Views - The View does not synchronize edit value changes with the data controller in the OnEditChanged ...and a grid item's Properties.ImmediatePost property is set to True...
scikit-learn is a Python module for machine learning built on top of SciPy and distributed under the 3-Clause BSD license.
What Is a Subquery? 4-3 Subqueries 4-4 Using a Subquery 4-5 Multiple-Column Subqueries 4-6 Column Comparisons 4-7 Pairwise Comparison Subquery 4-8 Nonpairwise Comparison Subquery 4-9 Using a Subquery ...
Clause-view个人中心、设置常用的itemview
[Err] 1055 – Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ’ which is not functionally dependent on columns in GROUP ...
-s, --string String to match in page when the query is valid Method: --method=PUT Select to use PUT method Modes: --dbs Enumerate databases MySQL v5+ --schema Enumerate Information_schema ...
Intrinsic Safety Standards Analysis
Japanese relative clause constructions (RCC’s) are defined as being the NP’s of structure ‘S NP’, noting the lack of a relative pronoun or any other explicit form of noun-clause demarcation. ...
data-science-at-the-command-line, 在 命令行,数据科学 命令行 中的数据科学 这个库包含了数据科学中的虚拟机。数据。脚本和自定义命令行工具,这些工具在的数据科学中。许可证BSD 2 -Clause