Open
Description
I have relationship defined on WorkoutResults model
public function unfinishedExercises()
{
$exercises = $this->exercises();
$id = $this->id;
return $exercises->whereDoesntHave('exercisesResults', function ($query) use ($id) {
$query->where('workout_result_id', $id);
});
}
In WorkoutResultSchema, I define the relationship field
HasMany::make('unfinished_exercises', 'unfinishedExercises')->type('exercises'),
The issue I'm facing:
- $this in the unfinishedExercises method is an empty model.
- Consequently, $this->id is null, so the filtering in the whereDoesntHave clause doesn't work as expected.
After some debugging, I found that the problem only occurs when this relationship is requested over the api.
When using the relationship in tinker, $this
is defined correctly, and the filtering works as expected.
If I request this relationship from workout-results/:id?include=unfinished_exercise
endpoint, the filtering doesn't happen, I get all exercises.
Metadata
Metadata
Assignees
Labels
No labels