php - Yii: relate n:m on both sides of an AR -


for better user experience, didn't want make casual pm system, group conversations. , added feature, being able pm multiple people @ once. requested multiple times. created this:

/*     user conversations          1 conversation         has many conversation members             has many users         has many private messages          1 private message         has 1 conversation          1 user         has many conversation member             has 1 conversation */ create table if not exists `tbl_user_pm_conv_members` (     `user_id` int(11),     `conv_id` int(11) ); create table if not exists `tbl_user_pm_conv` (     `id` int(11) not null auto_increment,     `owner_id` int(11) not null,     `subject` varchar(255) not null,     primary key (`id`) ); create table if not exists `tbl_user_pm_msg` (     `id` int(11) not null auto_increment,     `conv_id` int(11) not null,     `from_id` int(11) not null,     `body` text not null,     `sent` timestamp not null default current_timestamp,     primary key (`id`) ); 

i hope makes sense...

now, wanted setup n:m relation in yii (1.1.16 currently). no matter do, not want resolve.

in user.php:

public function relations() {     return array(         'profile'=>array(self::has_one, 'userprofile', 'uid'),         'updates'=>array(self::has_many, "userupdate", "tid"),         'permissions'=>array(self::has_many, "userpermissions", "uid"),         'settings'=>array(self::has_one, "usersettings", "id"),         'convos'=>array(             self::many_many, "privateconversation",             "tbl_user_pm_conv_members(id,id)",         )     ); } 

by yii's logic, fks should have been user_id , convo_id, resulting in tbl_user_pm_conv_members(user_id, convo_id). not have mysql constraints set, haven't understood them yet.

when try print_r($user->convos), this:

2015/04/28 23:49:01 [error] [system.db.cdbcommand] cdbcommand::fetchall() failed: sqlstate[42s22]: column not found: 1054 unknown column 'convos_convos.id' in 'on clause'. sql statement executed was: select `convos`.`id` `t1_c0`, `convos`.`owner_id` `t1_c1`, `convos`.`subject` `t1_c2` `tbl_user_pm_conv` `convos`  inner join `tbl_user_pm_conv_members` `convos_convos` on (`convos_convos`.`id`=:ypl0) , (`convos`.`id`=`convos_convos`.`id`). 2015/04/28 23:49:01 [error] [exception.cdbexception] exception 'cdbexception' message 'cdbcommand failed execute sql statement: sqlstate[42s22]: column not found: 1054 unknown column 'convos_convos.id' in 'on clause'' in /users/ingwie/work/bird3/php_modules/yiisoft/yii/framework/db/cdbcommand.php:543 

i lost. right way set n:m relation?

you have error in:

"tbl_user_pm_conv_members(id,id)", 

it should be:

"tbl_user_pm_conv_members(user_id,conv_id)", 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -