user(id, name)shop(id, name)user_shop(user_id,shop_id)
class usermodel extends relationmodel { protected $_link = array( 'shop' => array( 'mapping_type' => self::many_to_many, 'relation_table' => '__user_shop__', ) }
怎么没有效果啊?
sql调试是这样的:
[user] show columns from `tb_user` (executetime: 0.009001s ) [user] insert into `tb_user` (`name`,`password`) values ('xiak','qqqqqq') (executetime: 0.117007s ) [shop] show columns from `tb_shop` (executetime: 0.013001s ) [shop] insert into tb_user_shop (user_id,shop_id) select a.id,b.id from tb_user as a ,tb_shop as b where a.id =45 and b.id in (1) (executetime: 0.001000s )
手册上说 当many_to_many时,不建议使用关联插入。是什么意思啊?
回复内容: $u = d('user'); $u->name = 'xiak'; $u->password = 'qqqqqq'; $u->shop = array( 'gg' => '1', ); $u->relation(true)->add($data);
user(id, name)shop(id, name)user_shop(user_id,shop_id)
class usermodel extends relationmodel { protected $_link = array( 'shop' => array( 'mapping_type' => self::many_to_many, 'relation_table' => '__user_shop__', ) }
怎么没有效果啊?
sql调试是这样的:
[user] show columns from `tb_user` (executetime: 0.009001s ) [user] insert into `tb_user` (`name`,`password`) values ('xiak','qqqqqq') (executetime: 0.117007s ) [shop] show columns from `tb_shop` (executetime: 0.013001s ) [shop] insert into tb_user_shop (user_id,shop_id) select a.id,b.id from tb_user as a ,tb_shop as b where a.id =45 and b.id in (1) (executetime: 0.001000s )
手册上说 当many_to_many时,不建议使用关联插入。是什么意思啊?
难道就没有人跟我一样,觉得分拆sql再加事务才是最好的方案吗,关联的sql其它人看起来是不是很受罪呢
