model relation different id help

how to add relationship with these two tables if the primary key of the first table has

a different column name in the second table it is being referred to

e.g

Person

personid(pk),fname,lname,age

Job

jobid(pk),humanid(fk),description

in that example above, the humanid column’s value in the job table is the the personid from the first table…

so how to create a relation ship in this two table?

I tried




//PERSON MODEL

    public function relations() {

        return array(

            'job' => array(self::HAS_ONE,'Job','jobid')

        );

    }







//JOB MODEL

   public function relations(){

       return array(

           'person' => array(self::BELONGS_TO,'Person','personid')

        );

   }




this doesn’t work…any solutions without having to rename the db columns in my database?

Hello In the job model

You have to declare variable

Public $fname;

then add this variable in the Search in the rules.

‘Rel_name’ => array(self::BELONGS_TO, ‘Job’, ‘human_id’),

$criteria->with = array(‘Rel_name’);

$criteria->compare(‘Rel_title.title’,$this->title,true);

then as per this add in the view file…

thats it

Thanks