第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Laravel HasMany WhereNotIn Query

Laravel HasMany WhereNotIn Query

PHP
蠱毒傳說 2022-08-05 15:50:28
問題:我正在嘗試查詢?nèi)藛T類型以查找未關(guān)聯(lián)人員的所有課程。我有 4 張桌子人人員類型課程People_CoursesPeopleType_Courses我有以下關(guān)系人物模型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();我的回答:完整性約束沖突:1052 IN/ALL/ANY 子查詢中的列“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 回答

?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

在處理在查詢中選擇的具有相似列名的關(guān)系時(shí),需要通過在列中指定表名來解決多義性。例如:

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


查看完整回答
反對(duì) 回復(fù) 2022-08-05
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)