Answer the question
In order to leave comments, you need to log in
Search in Yii by argument with MANY_MANY relation
In the model (Part) there is a connection with another model (CarModel) of the form
'models'=>array(self::MANY_MANY, 'CarModel', 'part_to_model(p_id, m_id)')
what method to use for CDbCriteria in this case?
or ride $criteria->compare('models.name', $this->model)
?
In the last construction, it is annoying that models will return not one object, but an array.
Answer the question
In order to leave comments, you need to log in
I would do a search like this:
And I brought it to CGridView,
and an additional method in the model, which will collapse the array of model values in a row:
I did something similar in a bunch of movies + genres.
$criteria->together=true;
$criteria->with=array('CarModel');
$criteria->compare('m_id',$this->m_id);
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
...
array(
'name' => 'CarModel',
'filter'=> false,
'value' => ' $data->getCarModel ',
),
),
)); ?>
public function getCarModel($sSep = ', ') {
$aRes = array();
foreach ($this->CarModel as $itm) {
$aRes[] = $itm->name;
}
return implode($sSep, $aRes);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question