简体   繁体   中英

Select not working in Yii CDbCriteria

I have two related table and I have to display data from both trough a join query. I have this GridView that is "working" when i have to do the search, so that's mean if I have to search into a field from the joined table, it works and shows the right result, but I am not able to show all the column from both table.

Here is the error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'pratiche'. The SQL statement executed was: SELECT pratiche.* FROM pratiche t LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10

As you can see there is t after pratiche , so it fail the query. What's the problem?

public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria->select = "pratiche.*,clienti.*";

    $criteria->join='LEFT JOIN clienti ON id_cliente = clienti.id';

    $criteria->compare('id_pratiche',$this->id_pratiche,true);
    //this is the fild that should be shown(from the joined table)
    $criteria->compare('codice_fiscale',$this->codice_fiscale,true);

    $criteria->select = "pratiche.*";
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}

SOLVED! Wrong way to set the criteria:

$criteria->select=array('id_pratiche','data_creazione','stato_pratica','nome','cognome');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM