There are three tables
Device { id_device:primary key, name, id_type } DevicePc { id_device_pc, mb, cpu, ram } DeviceType { id_device_type, type } Those. there is some device Device, if this is a PC device, then DevicePC is filled and each device has a type from the DeviceType table. I can not create a connection between Device and Device.
I write this:
class Device extends CActiveRecord{ public function relations() { return array( 'devicepc' => array(self::BELONGS_TO, 'DevicePc', 'id_device'), 'devicetype' => array(self::BELONGS_TO, 'DeviceType', 'id_type'), ); } } class DevicePc extends CActiveRecord{ public function relations(){ return array( 'device' => array(self::BELONGS_TO, 'Device', 'id_device_pc'), ); } } class DeviceType extends CActiveRecord{ public function relations() { return array( 'device' => array(self::BELONGS_TO, 'Device', 'id_device_type'), ); } } There is a connection between Device and DeviceType, but not with DevicePc.
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'devicepc.' in 'on clause'. The SQL statement executed was: SELECT `t`.`id_device` AS `t0_c0`, `t`.`id_organization` AS `t0_c1`, `t`.`id_branch` AS `t0_c2`, `t`.`id_department` AS `t0_c3`, `t`.`id_cabinet` AS `t0_c4`, `t`.`id_employee` AS `t0_c5`, `t`.`id_type` AS `t0_c6`, `t`.`name` AS `t0_c7`, `t`.`description` AS `t0_c8`, `t`.`inv_number` AS `t0_c9`, `t`.`sn` AS `t0_c10`, `t`.`year` AS `t0_c11`, `t`.`end_varantly_yesr` AS `t0_c12`, `t`.`service` AS `t0_c13`, `t`.`expluatation` AS `t0_c14`, `t`.`expluatation_data` AS `t0_c15`, `t`.`private` AS `t0_c16`, `t`.`break` AS `t0_c17`, `devicepc`.`id_device_pc` AS `t1_c0`, `devicepc`.`mb` AS `t1_c1`, `devicepc`.`cpu_name` AS `t1_c2`, `devicepc`.`cpu_p` AS `t1_c3`, `devicepc`.`hdd_name` AS `t1_c4`, `devicepc`.`hdd_p` AS `t1_c5`, `devicepc`.`ram_name` AS `t1_c6`, `devicepc`.`ram_p` AS `t1_c7`, `devicepc`.`video_name` AS `t1_c8`, `devicepc`.`video_p` AS `t1_c9`, `devicepc`.`cdrom_name` AS `t1_c10`, `devicepc`.`lan_name` AS `t1_c11`, `devicepc`.`os` AS `t1_c12`, `devicepc`.`net_name` AS `t1_c13`, `devicepc`.`ip` AS `t1_c14`, `devicetype`.`id_device_type` AS `t2_c0`, `devicetype`.`name` AS `t2_c1`, `devicetype`.`description` AS `t2_c2` FROM `t_devices` `t` LEFT OUTER JOIN `t_device_pc` `devicepc` ON (`t`.`id_device`=`devicepc`.``) LEFT OUTER JOIN `t_devices_types` `devicetype` ON (`t`.`id_type`=`devicetype`.`id_device_type`) Why is this condition empty? What have I done wrong?
t_device_pc` `devicepc` ON (`t`.`id_device`=`devicepc`.``)