Skip to content

Morphable relation with additional conditions (probably cache key bug) #265

@smapod

Description

@smapod

Describe the bug
I guess that lmc not adding additional conditions to cache key in morph relations. Look at query. Product has Price (morphable). LMC returns same row/object that was cached first for different conditions. For example, if retail price was cached first, LMC will return retail price, when you are expecting wholesale price. And vice versa, if wholesale price was cached first, LMC will return wholesale price, when you are expecting retail price.

Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:

$products = Product
            ::with([
                'price' => function($query){
                    $query->where('type', request()->has('wholesale') ? 'wholesale' : 'retail');
                }
            ])
            ->where('category_id', $current)
            ->get();

Environment

  • PHP: 7.1.*
  • OS: macOS latest
  • Laravel: 5.8.*
  • Model Caching: latest

Additional context

I created new testing repo to reproduce the problem, instruction in readme https://github.com/smapod/lmc.

Thanks!

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions