fastadmin 一对一和一对多关联模型查询

视频地址

一对一查询:https://www.bilibili.com/video/BV1gL4y1p7w3/

一对多查询:https://www.bilibili.com/video/BV1kq4y16789/

 

一对一

文档地址:https://doc.fastadmin.net/doc/controller.html#toc-4

hasOne('关联模型名','本表外键名','本表主键名',['模型别名定义'],'join类型');
belongsTo('关联模型名','本表外键名','关联表主键名',['模型别名定义'],'join类型');

样例:4个表 fa_stuclass fa_student fa_studentmoney fa_stuscore
主表为:fa_student
实现:操作学生主表,增删改查 学费表和成绩表,查询班级表

关联查询

控制器里

protected $relationSearch = true;
 
/**
 * 快速搜索时执行查找的字段
 */
protected $searchFields = 'id,admin.username';

关联写入(新增)

$this->model->stuscore()->save(["score"=>111,"student_id"=>$this->model->id]);
 $this->model->studentmoney()->save(["money"=>12,"student_id"=>$this->model->id]);

关联修改

© 版权声明
THE END
喜欢就支持一下吧
点赞16 分享
评论 共1条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    请登录后查看评论内容