This seems to be the problem you want to solve (the first part of the thread).
So in short, create a relation to the table itself, and you should be able to access the name.
Don’t forget to create a public variable in your model that holds the parentName, like e.g. explained here.
Model:
public $parentName
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(
'selfParent' => array(self::BELONGS_TO, 'yourtable', 'parentId'),
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('parentId',$this->parentId);
$criteria->compare('name',$this->name,true);
//Add this
$criteria->compare('parentName', $this->selfRelation->parentName, true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Note that I didn’t know your base table name, so you have to fill it in.
On searching and filtering with related models you can find a lot of the forums. I have the feeling you will want to do this next. You might wanna read this blog post: