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`.``) 

    1 answer 1

    1. Question - MySql DB and table type MyIsam?
    2. Why not use InnoDB with foreign keys?
    3. Gii generator will create the necessary connections itself
    4. + To all the data integrity will be much higher.

    Well, if you need to say so in relations, which field from the Device table, and which field from the Devicepc table should be linked.

    If you use the search on the forum, I have already answered a similar question.

    // upd

    Is this not your question by chance? One straight 1: 1

    • Thanks for the answer. I will also add that I do not have a primary key field in the Devicepc table, so the connection did not work with a foreign key. Added id: PK field and it all worked. Thank you - Dmitry Galushko
    • @ Dmitry Galushko, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Artem