0

I have a User, Profile, Teacher, and Student models. Database looks as follows:

enter image description here

In the relations function of my Teacher and Student models, I would like to have:

'profile' => array(self::HAS_ONE, 'Profile', 'user_id', 'condition' => 'profile.user_id = 'teacher.user_id'),

Basically, I would like to write something that would output the same result as the following SQL query:

SELECT * FROM teacher, profile WHERE teacher.user_id = profile.user_id

and

SELECT * FROM student, profile WHERE student.user_id = profile.user_id
tshepang
  • 12,111
  • 21
  • 91
  • 136
TechMafioso
  • 135
  • 4
  • 16
  • And what is the problem? You can have the `condition` block there. It should work. – Pentium10 Feb 02 '14 at 07:39
  • @Pentium10 The problem with this is the following: `CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'teacher.user_id' in 'where clause'.` – TechMafioso Feb 02 '14 at 10:19
  • You need to sort out the aliases you put there. If you are in your Teacher model, then the table alias is `t`, you should have `t.user_id`. – Pentium10 Feb 02 '14 at 10:38
  • @Pentium10 Tried but returned `Column not found: 1054 Unknown column 't.user_id' in 'where clause'` – TechMafioso Feb 02 '14 at 10:58
  • Have you tried adding 'with'=>'teacher' to your relation? Your error about unknown 'teacher' column tells that there's no JOIN happening – apoq Feb 02 '14 at 12:24

0 Answers0