0

嗨,我想从表中选择以下带下划线的值。我试过但它不起作用.... 在此处输入图像描述

$criteria = new CDbCriteria;       

    $criteria->select = array('description', 'id','rate','item_unit_id');
    $criteria->with=array("item_unit","color");
    $criteria->together = true; 
    $criteria->addSearchCondition("description", $_GET['query']);

    $criteria->limit = $this->limit;

    $items = Item::model()->findAll($criteria);
    $suggestions = array();
    $x=0;
    foreach ($items as $c) {
        $suggestions[$x]['value'] = $c->description;
        $suggestions[$x]['id'] = $c->id;
        $suggestions[$x]['rate'] = $c->rate;
        $suggestions[$x]['unit'] = $c->item_unit->name;
        $x++;
    }
4

1 回答 1

3

好吧,如果您阅读过您会知道的文档,但是因为您没有阅读过,所以您没有阅读过 :)

但是,这可能会帮助您:

$criteria->select = 't.id, t.description, t.rate, t.code, color.name, item_unit.name';
$criteria->with = array(
    "item_unit" => array(
        'together' => true,
        'joinType' => 'INNER JOIN'
    ),
    "color" => array(
        'together' => true,
        'joinType' => 'INNER JOIN',
    )
); 

$criteria->addSearchCondition("t.description", $_GET['query']);
$criteria->limit = $this->limit;

$items = Item::model()->findAll($criteria); 
于 2013-07-09T13:40:09.713 回答