tp6的with关联使用(删查),insertAll批量增加
转自 https://www.cnblogs.com/bushui/p/13173785.html
1、with的使用
Thinkphp可以进行关联操作,数据库中需要用到join连接查询时候,用thinkPHP框架的关联查询可以有效的提高查询效率,下面是常用的关联:
(1)hasOne:有一个,A 有一个 B(一对一关联)
(2)hasMany:有很多,A 有很多 B(一对多关联)
(3)belongsTo: 多个(或一个)A 属于 B(属于,相当与多对一)
(4)belongsToMany:多对多关联
这里有两个表:comment(评论表)、article(文章表)
#文章
create table article
(
id int primary key AUTO_INCREMENT comment "ID",
title varchar(255) comment '标题',
content text comment '内容',
)
#评论
create table comment
(
id int primary key AUTO_INCREMENT comment "ID",
msg varchar(255) comment '评论内容',
article_id int comment '文章ID',
art_sum int
)


浙公网安备 33010602011771号