play表字段:
id type
type表字段:
id title
play表中的type和type表中的id进行关联。
thinkphp5中的模型定义如下:
play模型:
class Play extends Model
{
protected $table = 'wx_play';
public function type2()
{
return $this->hasOne("Type", "id", "type");
}type模型:
class Type extends Model
{
protected $table = 'wx_type';
}注意:
play模型中的type2函数,不能写成type,不然会跟play表中的type字段冲突,导致只查询到play表中的字段,而不是type表的对象。
根据thinkphp5的文档说明:
提示:
Play模型的 type2 方法就是一个关联定义方法,方法名可以随意命名,但注意要避免和Play 模型对
象的字段属性冲突。
Copyright © 2019- huatuo6.cn 版权所有 赣ICP备2024042791号-9
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务