1

我有一张用于办公室部门之间发票跟踪的表格。一旦我注册发票,就会将交易插入到表中。我转发到后勤办公室并插入另一笔交易。在表中,我有 currentLocationId、nextlocationId、timein、timeout、action。当我转发发票时,我不会更新之前注册发票的记录,但是一旦我转发了发票,我就需要它退出队列。请记住,注册的初始事务是完整的,没有更新,我如何在 YII 模型中过滤以仅获取已注册但尚未转发的记录?

以下是我的模型搜索。

 public function showPending($id)
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.


        $criteria=new CDbCriteria;
                $criteria->with = array('invoices');
                $criteria->together = true;
        $criteria->compare('InvoiceTrackingID',$this->InvoiceTrackingID);
        $criteria->compare('invoices.TrackingCode',$this->TrackingCode);
        $criteria->compare('TimeInStamp',$this->TimeInStamp,true);
        $criteria->compare('TimeOutStamp',$this->TimeOutStamp,true);
        $criteria->compare('Comments',$this->Comments,true);
        $criteria->compare('CurrentUnitLocationID',$this->CurrentUnitLocationID = $id); // see if the invoice is in your unit location
                $criteria->compare('UserID',$this->UserID);
        $criteria->compare('TrackingActionID',$this->TrackingActionID = 2);  // fetch only invoices whose action was to forward to display

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
4

1 回答 1

1

首先,我需要查看您的表格,但无论如何您需要为您的条件添加条件,并且会像这样:

$criteria->addCondition(" your condition here ");

您也可以使用这样的复杂条件:例如

$criteria->addCondition(" ticket_id not in (select ticket_id  from table where coulmn=$section_id ) ");

*注意:在第一行添加条件语句,如:

public function showPending($id)
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.


        $criteria=new CDbCriteria;

$criteria->addCondition(" your condition here ");
                $criteria->with = array('invoices');
                $criteria->together = true;
        $criteria->compare('InvoiceTrackingID',$this->InvoiceTrackingID);
        $criteria->compare('invoices.TrackingCode',$this->TrackingCode);
        $criteria->compare('TimeInStamp',$this->TimeInStamp,true);
        $criteria->compare('TimeOutStamp',$this->TimeOutStamp,true);
        $criteria->compare('Comments',$this->Comments,true);
        $criteria->compare('CurrentUnitLocationID',$this->CurrentUnitLocationID = $id); // see if the invoice is in your unit location
                $criteria->compare('UserID',$this->UserID);
        $criteria->compare('TrackingActionID',$this->TrackingActionID = 2);  // fetch only invoices whose action was to forward to display

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
于 2013-06-06T13:15:12.423 回答