php - laravel belongsToMany跨表查询问题
本文介绍了php - laravel belongsToMany跨表查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
现在有三个表
post
--id
--post_data
TermRelationships
--object_id
--term_taxonomy_id
Terms
--term_id
--name
其中post的id对应TermRelationships的object_id
terms的term_id对应term_taxonomy_id。
我在Terms的模型当中设置protected $primaryKey = 'term_id';
我想通过post获得terms的name,设置了belongsToMany('TermRelationships','Terms','term_taxonomy_id','term_id')
查询不出来。
请问是为什么?是我第三个参数和第四个参数传递的不对吗?
解决方案
belongsToMany('Terms','TermRelationships','object_id','term_taxonomy_id')
这篇关于php - laravel belongsToMany跨表查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文