亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 有很多 WhereNotIn 查詢

Laravel 有很多 WhereNotIn 查詢

PHP
ibeautiful 2022-07-22 15:56:06
問題:我正在嘗試查詢 PeopleType 以查找與人員無關的所有課程。我有 4 張桌子人們人員類型培訓班People_CoursesPeopleType_Courses我有以下關系人物模型public function getPeopleType() {  return $this->belongsTo('App\PeopleType','type_id');}public function getCourses() {  return $this->belpngsToMany('App\Course','People_Courses','person_id','course_id');}PEOPLE_TYPE 模型public function getPeople() {  return $this->hasMany('App\Person','type_id');}public function getCourses() {  return $this->belpngsToMany('App\Course','PeopleType_Courses','people_type_id','course_id');}我的嘗試:$peopleType = \App\PeopleType::FindOrFail(1);$courses = $peopleType->getCourses()->whereNotIn('id', function($q) use($person) {                $q->select('course_id')                  ->from('People_Courses')                    ->where('person_id', $person->id);           })->get();我的回復:完整性約束違規:IN/ALL/ANY 子查詢中的 1052 列“id”不明確人員課程表示意圖Schema::create('People_Courses', function (Blueprint $table) {   $table->increments('id');   $table->integer('course_id');   $table->integer('person_id'););PeopleType_Courses 表示意圖Schema::create('PeopleType_Courses', function (Blueprint $table) {   $table->increments('id');   $table->integer('course_id');   $table->integer('people_type_id'););
查看完整描述

1 回答

?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

當您處理在查詢中選擇了相似列名的關系時,您需要通過指定列的表名來解決歧義。例如:

$peopleType->getCourses()->whereNotIn('courses.id', function($q)...  //courses.id


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 196 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號