public function add(){// 构建user对象$user = new User;$user->name = 'xiaoqiang';$user->password = '123456';$user->country_id = 1;//构建user_info对象$user_info=new UserInfo;$user_info->tel = '1326698188';$user_info->email = '821832183@qq.com';$user_info->addr = '北京';// 绑定关联关系// $user->user_info = $user_info;$user->userInfo = $user_info;//关联新增 关联属性名(需要和$user->user_info一致)// $user->together('user_info')->save();$user->together('userInfo')->save();}
[ DB ] CONNECT:[ UseTime:0.002465s ] mysql:host=127.0.0.1;dbname=relation;charset=utf8
[ SQL ] SHOW COLUMNS FROM `it_user` [ RunTime:0.002611s ]
[ SQL ] INSERT INTO `it_user` (`name` , `password` , `country_id`) VALUES ('xiaoqiang' , '123456' , 1) [ RunTime:0.001022s ]
[ SQL ] SHOW COLUMNS FROM `it_user_info` [ RunTime:0.003473s ]
[ SQL ] INSERT INTO `it_user_info` (`tel` , `email` , `addr` , `user_id`) VALUES ('1326698188' , '821832183@qq.com' , '北京' , 7) [ RunTime:0.000701s ]
public function upd(){//查询id=6的user表的记录$user = User::get(6);$user->password = '666666';$user->user_info->tel = '666666666';$user->together('user_info')->save();}
[ DB ] CONNECT:[ UseTime:0.002211s ] mysql:host=127.0.0.1;dbname=relation;charset=utf8
[ SQL ] SHOW COLUMNS FROM `it_user` [ RunTime:0.002237s ]
[ SQL ] SELECT * FROM `it_user` WHERE `id` = 6 LIMIT 1 [ RunTime:0.000814s ]
[ SQL ] SHOW COLUMNS FROM `it_user_info` [ RunTime:0.002690s ]
[ SQL ] SELECT * FROM `it_user_info` WHERE `user_id` = 6 LIMIT 1 [ RunTime:0.000839s ]
[ SQL ] UPDATE `it_user` SET `password` = '666666' WHERE `id` = 6 [ RunTime:0.001811s ]
[ SQL ] UPDATE `it_user_info` SET `tel` = '666666666' WHERE `user_id` = 6 [ RunTime:0.001017s ]