更新 CGridView yii1 框架
Update CGridView yii1 framework
已经尝试了所有可能的选项,但关系不起作用。但是我得到这个错误
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous. The SQL statement executed was: SELECT t
.id
AS t0_c0
, t
.user_id
AS t0_c1
, t
.store_id
AS t0_c2
, t
.status_id
AS t0_c3
, t
.bill_to_id
AS t0_c4
, t
.total
AS t0_c5
, t
.new
AS t0_c6
, t
.pay_method_id
AS t0_c7
, t
.created
AS t0_c8
, t
.updated
AS t0_c9
, t
.billing_to_first
AS t0_c10
, t
.billing_to_last
AS t0_c11
, t
.billing_to_fax
AS t0_c12
, t
.cc_last_four
AS t0_c13
, t
.check_image_id
AS t0_c14
, t
.comments
AS t0_c15
, t
.warning_id
AS t0_c16
, t
.artworkRec
AS t0_c17
, t
.proofSent
AS t0_c18
, t
.proofApprvd
AS t0_c19
, t
.inHands
AS t0_c20
, orderItems
.id
AS t1_c0
, orderItems
.order_id
AS t1_c1
, orderItems
.product_id
AS t1_c2
, orderItems
.factory_id
AS t1_c3
, orderItems
.qty
AS t1_c4
, orderItems
.price
AS t1_c5
, orderItems
.logo_name
AS t1_c6
, orderItems
.po_number
AS t1_c7
, orderItems
.art_id
AS t1_c8
, orderItems
.art_status_id
AS t1_c9
, orderItems
.send_proof
AS t1_c10
, orderItems
.art_comments
AS t1_c11
, orderItems
.rush_option_id
AS t1_c12
, orderItems
.special_instructions
AS t1_c13
, orderItems
.misc_charge_name
AS t1_c14
, orderItems
.misc_charge_amount
AS t1_c15
FROM tbl_order
t
LEFT OUTER JOIN tbl_order_item
orderItems
ON (orderItems
.order_id
=t
.id
) WHERE (orderItems.po_number=213) ORDER BY id DESC LIMIT 10
我有一个table。
enter image description here
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'invoices' => array(self::HAS_MANY, 'Invoice', 'order_id'),
'billTo' => array(self::BELONGS_TO, 'Address', 'bill_to_id'),
'checkImage' => array(self::BELONGS_TO, 'Files', 'check_image_id'),
'payMethod' => array(self::BELONGS_TO, 'PayMethod', 'pay_method_id'),
'status' => array(self::BELONGS_TO, 'Status', 'status_id'),
'store' => array(self::BELONGS_TO, 'Websites', 'store_id'),
'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
'warning' => array(self::BELONGS_TO, 'WarningsLog', 'warning_id'),
'orderChangeLogs' => array(self::HAS_MANY, 'OrderChangeLog', 'order_id'),
'orderItems' => array(self::HAS_MANY, 'OrderItem', 'order_id'),
'shipments' => array(self::HAS_MANY, 'Shipment', 'order_id'),
'warningsLogs' => array(self::HAS_MANY, 'WarningsLog', 'order_id'),
);
}
public function search($array = null)
{
$criteria=new CDbCriteria;
$criteria->compare('t.id',$this->id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('store_id',$this->store_id);
$criteria->compare('status_id',$this->status_id);
$criteria->compare('bill_to_id',$this->bill_to_id);
$criteria->compare('total',$this->total,true);
$criteria->compare('new',$this->new);
$criteria->compare('pay_method_id',$this->pay_method_id);
$criteria->compare('created',$this->created,true);
$criteria->compare('updated',$this->updated,true);
$criteria->compare('billing_to_first',$this->billing_to_first,true);
$criteria->compare('billing_to_last',$this->billing_to_last,true);
$criteria->compare('billing_to_fax',$this->billing_to_fax,true);
$criteria->compare('cc_last_four',$this->cc_last_four);
$criteria->compare('check_image_id',$this->check_image_id);
$criteria->compare('comments',$this->comments,true);
$criteria->compare('warning_id',$this->warning_id);
$criteria->compare('artworkRec',$this->artworkRec,true);
$criteria->compare('proofSent',$this->proofSent,true);
$criteria->compare('proofApprvd',$this->proofApprvd,true);
$criteria->compare('inHands',$this->inHands,true);
$criteria->with = array('orderItems');
// $criteria->compare('orderItems.order_id', $this->id, true);
$criteria->addCondition('orderItems.po_number=213');
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'id DESC',
),
));
}
我很乐意提供任何帮助
'sort'=>数组(
'defaultOrder'=>'t.id DESC',
),
已经尝试了所有可能的选项,但关系不起作用。但是我得到这个错误
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous. The SQL statement executed was: SELECT
t
.id
ASt0_c0
,t
.user_id
ASt0_c1
,t
.store_id
ASt0_c2
,t
.status_id
ASt0_c3
,t
.bill_to_id
ASt0_c4
,t
.total
ASt0_c5
,t
.new
ASt0_c6
,t
.pay_method_id
ASt0_c7
,t
.created
ASt0_c8
,t
.updated
ASt0_c9
,t
.billing_to_first
ASt0_c10
,t
.billing_to_last
ASt0_c11
,t
.billing_to_fax
ASt0_c12
,t
.cc_last_four
ASt0_c13
,t
.check_image_id
ASt0_c14
,t
.comments
ASt0_c15
,t
.warning_id
ASt0_c16
,t
.artworkRec
ASt0_c17
,t
.proofSent
ASt0_c18
,t
.proofApprvd
ASt0_c19
,t
.inHands
ASt0_c20
,orderItems
.id
ASt1_c0
,orderItems
.order_id
ASt1_c1
,orderItems
.product_id
ASt1_c2
,orderItems
.factory_id
ASt1_c3
,orderItems
.qty
ASt1_c4
,orderItems
.price
ASt1_c5
,orderItems
.logo_name
ASt1_c6
,orderItems
.po_number
ASt1_c7
,orderItems
.art_id
ASt1_c8
,orderItems
.art_status_id
ASt1_c9
,orderItems
.send_proof
ASt1_c10
,orderItems
.art_comments
ASt1_c11
,orderItems
.rush_option_id
ASt1_c12
,orderItems
.special_instructions
ASt1_c13
,orderItems
.misc_charge_name
ASt1_c14
,orderItems
.misc_charge_amount
ASt1_c15
FROMtbl_order
t
LEFT OUTER JOINtbl_order_item
orderItems
ON (orderItems
.order_id
=t
.id
) WHERE (orderItems.po_number=213) ORDER BY id DESC LIMIT 10
我有一个table。 enter image description here
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'invoices' => array(self::HAS_MANY, 'Invoice', 'order_id'),
'billTo' => array(self::BELONGS_TO, 'Address', 'bill_to_id'),
'checkImage' => array(self::BELONGS_TO, 'Files', 'check_image_id'),
'payMethod' => array(self::BELONGS_TO, 'PayMethod', 'pay_method_id'),
'status' => array(self::BELONGS_TO, 'Status', 'status_id'),
'store' => array(self::BELONGS_TO, 'Websites', 'store_id'),
'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
'warning' => array(self::BELONGS_TO, 'WarningsLog', 'warning_id'),
'orderChangeLogs' => array(self::HAS_MANY, 'OrderChangeLog', 'order_id'),
'orderItems' => array(self::HAS_MANY, 'OrderItem', 'order_id'),
'shipments' => array(self::HAS_MANY, 'Shipment', 'order_id'),
'warningsLogs' => array(self::HAS_MANY, 'WarningsLog', 'order_id'),
);
}
public function search($array = null)
{
$criteria=new CDbCriteria;
$criteria->compare('t.id',$this->id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('store_id',$this->store_id);
$criteria->compare('status_id',$this->status_id);
$criteria->compare('bill_to_id',$this->bill_to_id);
$criteria->compare('total',$this->total,true);
$criteria->compare('new',$this->new);
$criteria->compare('pay_method_id',$this->pay_method_id);
$criteria->compare('created',$this->created,true);
$criteria->compare('updated',$this->updated,true);
$criteria->compare('billing_to_first',$this->billing_to_first,true);
$criteria->compare('billing_to_last',$this->billing_to_last,true);
$criteria->compare('billing_to_fax',$this->billing_to_fax,true);
$criteria->compare('cc_last_four',$this->cc_last_four);
$criteria->compare('check_image_id',$this->check_image_id);
$criteria->compare('comments',$this->comments,true);
$criteria->compare('warning_id',$this->warning_id);
$criteria->compare('artworkRec',$this->artworkRec,true);
$criteria->compare('proofSent',$this->proofSent,true);
$criteria->compare('proofApprvd',$this->proofApprvd,true);
$criteria->compare('inHands',$this->inHands,true);
$criteria->with = array('orderItems');
// $criteria->compare('orderItems.order_id', $this->id, true);
$criteria->addCondition('orderItems.po_number=213');
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'id DESC',
),
));
}
我很乐意提供任何帮助
'sort'=>数组( 'defaultOrder'=>'t.id DESC', ),