【问题标题】:Update CGridView yii1 framework更新 CGridView yii1 框架
【发布时间】:2016-01-29 16:20:59
【问题描述】:

已尝试所有可能的选项,但关系不希望工作。但是我得到了这个错误

CDbCommand 未能执行 SQL 语句:SQLSTATE[23000]:完整性约束违规:1052 order 子句中的列 'id' 不明确。执行的 SQL 语句是:SELECT t.id AS t0_c0, t.user_id AS t0_c1, t.store_id AS t0_c2, status_id1. AS t0_c3, t.bill_to_id AS t0_c4, t.total AS t0_c5, t.t.new AS t0_c6, @9876434342@, @987643 987654345 @,tcreated AS t0_c8tupdated AS t0_c9tbilling_to_first AS t0_c10tbilling_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, @98765436@AS, @9876454367@.@9876 987654370 @。warning_id AS t0_c16tartworkRec AS t0_c17tproofSent AS t0_c18tproofApprvd AS t0_c19t .inHands AS t0_c20, orderItems.id AS t1_c0, orderItems.order_id AS t1_c1, @9876543@1@.product_id AS @9876 987654394 factory_id AS t1_c3orderItems 987654398 t1_c4orderItemst1_c5orderItems $ 987654405 @,orderItemsorderItemsorderItemsorderItems .po_number AS t1_c7, orderItems.art_id AS t1_c8, orderItems.art_status_id AS t1_c9, @9876544@15@.send_proof AS send_proof9876 987654419 @ AS t1_c11orderItemsrush_option_id AS t1_c12orderItemsspecial_instructions AS t1_c13orderItemsmisc_charge_name AS t1_c14orderItemsmisc_charge_amount AS t1_c15 FROM tbl_order t LEFT OUTER JOIN tbl_order_item orderItems ON (orderItems.order_id=t.id) 哪里 (orderItems.poid_DESC)限制 10

我有一张桌子。 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',
        ),
    ));
}

我会很高兴得到任何帮助

【问题讨论】:

  • id 列在您的查询中使用了两次。将别名放在 id 之前,例如 u.id 也提交这一行 $criteria->with = array('orderItems');
  • 不太明白,可以举个完整的例子
  • 如果我添加它 $criteria->with = array('orderItems'); $criteria->alias = 'u.id';我有错误

标签: yii cgridview


【解决方案1】:

'排序'=>数组( 'defaultOrder'=>'t.id DESC', ),

【讨论】:

    猜你喜欢
    • 2016-04-07
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 2013-03-23
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多