Let’s say I have the situation:
A company has departments and departments have employees
Each respective table has
Id primary key and relations are defined by foreign keys using these Id numbers.
Now I have a CGridView of employees and I would like to show name of department he/she is working in (that is easy) as well as name of the company he/she belongs (difficult).
Well - in a grid I can show:
This is showing company names appropriately but no joy with filtering/sorting !!!
I am unable to construct working seach criteria in a model. Whatever I try - I get kind of ‘column not found’ SQL error.
So - how to overcome? It’s urgent!
Thanks ahead for suggestions!
Your problem is not that much clear to me, I think you are unable to sort and filter using relations.
Use of "with" clause can sort out your problem.
Take a look over here
How to use ‘with’ clause for relations
I am looking for Yii criteria syntax for:
SELECT COUNT(DISTINCT `t`.`id`)
FROM `employees` `t`
LEFT OUTER JOIN `departments` `department`
LEFT OUTER JOIN `companies` `company`
WHERE (`company`.`name` LIKE 'Hewlett%');
Actually, I have a problem with “WHERE” condition - I can’t find good way to put it into search criteria.
All right - finally I’ve got it: