I have a problem getting the pivot attributes of a polymorphic many to many relationship. Is this possible with this library?
Let's assume whe have four tables, Students, Teachers, Courses, and Coursables, where the last one can hold either a relation to a student or a teacher.
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL
);
CREATE TABLE Teachers (
TeacherID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL
);
CREATE TABLE Coursable (
CoursableID INT,
CoursableType VARCHAR(50) NOT NULL, -- 'Student' or 'Teacher'
CourseID INT,
Year INT NOT NULL,
Semester VARCHAR(10) NOT NULL, -- 'Spring' or 'Fall'
PRIMARY KEY (CoursableID, CoursableType, CourseID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
Title VARCHAR(100) NOT NULL
);
And in the model classes we have the relations setup like
(i) Course
#[LodataRelationship]
public function students(): MorphToMany
{
return $this->morphedByMany(Student::class, 'coursable')
->using(Coursable::class)
->withPivot(['semester', 'year']);
}
(ii) Student
#[LodataRelationship]
public function courses(): MorphMany
{
return $this->morphMany(Course::class, 'coursable')
->using(Coursable::class)
->withPivot(['semester', 'year']);
}
Is it possible with this library the query a course with all related students and teachers and with the pivot attributes?
When I try with a request like /odata/Courses(1)?$expand=teachers,students I get correctly all enrolled teachers and students, but without the pivot attributes.
I have a problem getting the pivot attributes of a polymorphic many to many relationship. Is this possible with this library?
Let's assume whe have four tables,
Students
,Teachers
,Courses
, andCoursables
, where the last one can hold either a relation to a student or a teacher.And in the model classes we have the relations setup like
(i) Course
(ii) Student
Is it possible with this library the query a course with all related students and teachers and with the pivot attributes?
When I try with a request like
/odata/Courses(1)?$expand=teachers,students
I get correctly all enrolled teachers and students, but without the pivot attributes.Any hints welcomed!