Skip to content

Dynamic local scopes in with clauses always returns same results, even if scope is different. #291

Open
@hyperized

Description

@hyperized

Describe the bug
I'm not sure if this is a feature request or bug. I hope you don't mind I put it in bugs.

We're currently using Dynamic Local Query scopes (https://laravel.com/docs/5.8/eloquent#local-scopes -> Dynamic scopes). However it seems that the cache key does not take the dynamic aspect into account, making it rather .. static.

I could imagine that the cache key generation method can check for additional parameters when generating the key as a possible solution?

Eloquent Query

public function scopeOfLesson($query, Lesson $lesson)
{
return $query->where('lesson_id', $lesson->id);
}
return Student::
where('id', 1)
->with(['progress' => static function (HasMany $model) use ($lesson) {
$model->ofLesson($lesson);
}])
->get();

The results is that when given two different $lessons that the cache results will return the result of the first requested $lesson.

Stack Trace
n/a

Environment

  • PHP: 7.2
  • OS: n/a
  • Laravel: 5.8
  • Model Caching: 0.7.0

Additional context
Thank you for making this package, we use it in every Laravel project to speed things up ❤️!

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions