返回主题表image字段信息以及相应的商品信息列表
来源:8-15 编写Theme详情接口
慕粉1472091201
2017-10-12
//跟据主题返回theme主题表image,himage两个字段信息以及deal相应的商品信息列表
public function getThemeInfo($themeId){
$theme=model('Theme')->get($themeId);
$result=$theme->deals()
->select();
echo $this->getLastSql();exit();
// ->where('theme_status',1)
// ->select();
//
// dump($result);exit();
// return $theme;
}
//定义theme and deal关联关系
public function deals(){
return $this->hasMany('deal','theme_id','id');
}控制层代码
public function getComplexOne($themeId){
// (new IDMustBePositiveInt())->goCheck();
$theme= model("Theme")->getThemeInfo($themeId);
if ($theme){
return $theme;
}else{
throw new MissException([
'msg' => '请求theme商品不存在',
'errorCode' => 40000
]);
}调试结果,
SELECT * FROM `o2o_deal` WHERE `theme_id` = 12
老师,我在model层定义了了theme与deal表是一对多的关系,怎样把这两个属性值绑定到模型关系上?
写回答
2回答
-
7七月
2017-10-12
我记得我当时分析的很清楚啊,还对着数据库表字段讲的,课程有看吗?
012017-10-12 -
7七月
2017-10-12
课程里的事例不就是一对多的么。。。比如商品和图片
00
相似问题