問題:我正在嘗試查詢 PeopleType 以查找與人員無關(guān)的所有課程。我有 4 張桌子人們?nèi)藛T類型培訓(xùn)班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();我的回復(fù):完整性約束違規(guī):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'););
Laravel 有很多 WhereNotIn 查詢
ibeautiful
2022-07-22 15:56:06