Hello,
I am new in yii… i am trying to check duplication record in create and update.
My table schema :
[b]Attributes tbl :
id, name[/b]
[b]
Project tbl :
id, name, proce[/b]
[b]
Project_attribute_price tbl :
id,attribute_id,project_id,price[/b]
i am trying to validation if project_id and attribute_id is same in create and update project_attribute_price.
My project_attribute_price model is :
class ProjectAttributesPrice extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'tblproject_attributes_price';
}
public function rules()
{
return array(
array('project_id, attribute_id, price', 'required'),
array('project_id, attribute_id', 'numerical', 'integerOnly'=>true),
array('price', 'numerical'),
array('id, project_id, attribute_id, price', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'projects'=>array(self::BELONGS_TO, 'Projects', 'project_id'),
'attribute'=>array(self::BELONGS_TO, 'Attributes', 'attribute_id'),
);
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'project_id' => 'Project',
'attribute_id' => 'Attribute',
'price' => 'Price',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('project_id',$this->project_id);
$criteria->compare('attribute_id',$this->attribute_id);
$criteria->compare('price',$this->price);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
Thanks in advance…