I am using Yii GridView filter and my data comes from Purcahses table. That tables realted to 1 .vendors 2 .clients Below are my relations in Purchases Model
'vendor' => array(self::BELONGS_TO, 'Vendors', 'Vendor'),
'client' => array(self::BELONGS_TO, 'Clientsinfo', 'clientID'),
and i am using that relations in my admin view , Below is code of admin.php file
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'purchases-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name' => 'Vendor',
'value' =>'$data->vendor->VendorName',
),
array(
'name' => 'clientID',
'value' =>'$data->client->Company'
),
array(
'name' => 'PurchaseType',
'value' => 'Purchasetype::model()->findByPk($data->PurchaseType)->PurchaseType',
'filter' => '',
),
),
));
and lastly here is model search function where is use with and together to get data from other tables
public function search() {
$criteria = new CDbCriteria;
$criteria->together = true;
$criteria->with = array('vendor');
$criteria->with = array('client');
$criteria->compare('PurchaseType', $this->PurchaseType);
$criteria->compare('vendor.VendorName', $this->Vendor, true);
$criteria->compare('client.Company', $this->clientID, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
Getting data from client successufully , but when i use vendor fitter it throw me error below
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column
'vendor.VendorName' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT t
.PurchaseID
) FROM purchases
t
LEFT OUTER JOIN clientsinfo
client
ON (t
.clientID
=client
.ClInfoID
) WHERE ((Vendor=:ycp0) AND (vendor.VendorName LIKE :ycp1)) (C:\xampp\htdocs\laurenparker\framework
\db\CDbCommand.php:543)
queryInternal('fetchColumn', 0, Array)
Youre overriding relations in criteria
. Change this:
$criteria->with = array('vendor');
$criteria->with = array('client');
To this:
$criteria->with = array('vendor', 'client');