您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

thinkphp关联模型 多对多 插入 怎么使用?????

2024/6/5 14:17:08发布15次查看
$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时,不建议使用关联插入。是什么意思啊?
回复内容: $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其它人看起来是不是很受罪呢
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product