Hey all,
I have a cgridview which populates values from a model called messagesnew but when i try the search option on attributes read, to, from , i get a error as attached
The relations of my tables are:-
My messagesnew relation:
CREATE TABLE `messagesnew` (
`messageId` int(11) NOT NULL AUTO_INCREMENT,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`read` tinyint(1) NOT NULL,
`to` varchar(45) DEFAULT NULL,
`from` varchar(45) DEFAULT NULL,
`title` varchar(45) DEFAULT NULL,
`content` varchar(45) DEFAULT NULL,
PRIMARY KEY (`messageId`),
KEY `fk_messagesnew_logindetailskasun_idx` (`to`),
CONSTRAINT `fk_messagesnew_logindetailskasun` FOREIGN KEY (`to`) REFERENCES `logindetailskasun` (`Username`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
My logindetailskasun relation
CREATE TABLE `logindetailskasun` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Password` varchar(45) DEFAULT NULL,
`Username` varchar(45) DEFAULT NULL,
`level` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `Username` (`Username`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
I have created the models for both my relations
relations for each table:-
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(
'to0' => array(self::BELONGS_TO, 'Logindetailskasun', 'to'),
);
}
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(
'messagesnews' => array(self::HAS_MANY, 'Messagesnew', 'to'),
);
}
action admin of my Messagesnew:-
public function actionAdmin()
{
$model=new Messagesnew('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Messagesnew']))
$model->attributes=$_GET['Messagesnew'];
$this->render('admin',array(
'model'=>$model,
));
}
The search for messagesnew is as follows :-
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('messageId',$this->messageId);
$criteria->compare('time',$this->time,true);
$criteria->compare('read',$this->read,true);
$criteria->compare('to',$this->to,true);
$criteria->compare('from',$this->from,true);
$criteria->compare('title',$this->title,true);
$criteria->compare('content',$this->content,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}