0
I have three tables:
students
------------
id INT
name VARCHAR
class
-----------
id INT
description VARCHAR
student_classes
--------
id INT
student_id (FOREIGN KEY of students.id)
class_id (FOREIGN KEY of class.id)
How can I return all table records class
that has no relationship of a particular student in student_classes
?
I get the value of student_id
in request.params.student_id
, I tried something like:
async getAvailableClassesOfAStudent({ request }){
const classes = await Database
.query()
.select('class.*')
.from('class')
.leftJoin('student_classes', 'class.id', 'student_classes.class_id')
.whereNotIn('student_classes.student_id', request.params.student_id)
return classes
}
I’m taking it back:
select "class". * from "class" left Join "student_classes" on "class"." id" = "student_classes"." class_id" Where "student_classes"." student_id" not in $1 - syntax error at or near "$1"