Ok, so I’m simplifying, but I have an interesting relationship that I can seem to find any discussion of.
Person
person_id
department_id
Department
department_id
division_id
Division
division_id
I want to set up a relationship in my Person record that gives me the Division they belong to. Any ideas? I already have the department relationship. That’s easy: array(self::BELONGS_TO, ‘Department’, ‘department_id’).
Yeah, I do this in several places, but I think I actually need a relationship like this for the search feature in my grid view. I have a gridview for Person where I added the column for division.
$criteria->compare('division.division_name',$this->divisionName,true),
...
$criteria->alias = 'person';
$criteria->join = 'left join department on person.department_id = department.department_id left join division on department.division_id = division.division_id';
If I leave Division out of the grid, I can just use $criteria->with = array(‘department’). But when I want to talk about Division, I need to join to it, and if I have with(‘department’) and try to mention department in the join line, it doesn’t know what I’m talking about, so I don’t use with and just specify the whole join myself.
I figure if I can get a relationship in Person for this Division, then I can do with = array(‘department’,‘division’) and go on my merry way, since this works for department.