5.0版本,多对多模型,显示“缺少关联表数据”

浏览:483 发布日期:2018/10/18 分类:求助交流 关键字: 多对多,模型,缺少关联表数据
teachers.php:
namespace app\admin\model;
use think\Model;

class Teachers extends Model
{
public function students(){
return $this->belongsToMany('Students','s_t','s_id','t_id');
}
}
students.php:
namespace app\admin\model;

use think\Model;

class Students extends Model
{
public function teachers(){
return $this->belongsToMany('Teachers','s_t','t_id','s_id');
}
}

teachers表:id,name,gender; students表:id,name,gender,hobby; 中间表:id,s_id,t_id;

index.php:
$s = Students::get(1);
$s->teachers()->save(['id'=>14,'name'=>'god','gender'=>0]);

运行结果,teachers表有添加1条记录,但中间表没有,而且提示:缺少关联表数据, 求大神帮帮我!!
最佳答案
评论( 相关
后面还有条评论,点击查看>>