您好我想从table.i中选择以下带下划线的值,但是它无效......
$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++;
}
答案 0 :(得分: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);