Помогите пожалуйста. В обновление записей в БД. Я еще чайник в yii.
У меня есть БД Car и Equipment.
Model Equipment
.......................................
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'Car' => array(self::BELONGS_TO, 'Car', 'Car_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'Equipment_id' => 'Equipment',
'Car_id' => 'Car',
'Category' => 'Category',
'Option_Name' => 'Option Name',
'Option' => 'Option',
);
}
.............................
Model Car
.......................
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'Comments'=>array(self::HAS_ONE, 'Comments', 'Car_id'),
'Equipment'=>array(self::HAS_MANY, 'Equipment', 'Car_id'),
'Image' => array(self::HAS_MANY, 'Image', 'Car_id'),
'ImageCount' => array(self::STAT, 'Image', 'Car_id','select' => 'COUNT(*)' ),
'Video' => array(self::HAS_MANY, 'Video', 'Car_id'),
'VideoCount' => array(self::STAT, 'Video', 'Car_id','select' => 'COUNT(*)' ),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'Car_id' => 'Car',
'Stock' => 'Stock',
'VIN' => 'Vin',
'Dealer' => 'Dealer',
'Type' => 'Type',
...............................
У базы Car есть несколько Equipment После вывода в view. Если изменены поля надо сохранить в БД Equipment.
View
...............................
<?php foreach ($model->Equipment as $Equipment): ?>
<tr>
<td><?php echo CHtml::activeCheckBox($Equipment,'Option').CHtml::encode($Equipment->Option_Name); ?></td>
<td><?php echo CHtml::error($Equipment,'Option'); ?></td>
</tr>
<?php endforeach; ?>
................................
контролер
.............
if(isset($_POST['Equipment']))
{
$modelEq=Equipment::model()->findall('Car_id=:Car_id', array(':Car_id'=>$id));
$modelEq->Car_id =$id;
$modelEq->attributes=$_POST['Equipment'];
if ($modelEq->save()) ;
}
................
Проблема в том что если у Car один Equipment, то тогда сохранение идет нормально. Но если у Car много Equipment то я не могу сохранить .