Closed
Description
Describe the bug
We are using left join as we need to allow sorting of each individual columns returned.
AFAIK this can't be supported using eager loading unless the sorting is done outside of SQL (Which is not very efficient).
The issue here is that results of the query are cached correctly in Redis but if we make changes to countries table, the cached item is not invalidated.
Can I confirm whether this is supported?
Here's a simplified schema for illustration:
Table: countries
+--------------+---------------+
| country_code | name |
+--------------+---------------+
| US | United States |
| JP | Japan |
+--------------+---------------+
Table: products
+----+--------+--------------+
| id | name | country_code |
+----+--------+--------------+
| 1 | apple | US |
| 2 | orange | JP |
+----+--------+--------------+
Model: Country
class Country extends CachedModel
{
public function products(): HasMany
{
return $this->hasMany(Product::class, 'country_code', 'country_code');
}
}
Model: Product
class Product extends CachedModel
{
public function country(): BelongsTo
{
return $this->belongsTo(Country::class, 'country_code', 'country_code');
}
}
Eloquent Query
Products::leftjoin('countries', 'country_code', '=', 'country_code')
->orderBy('countries.name');
Observations
Cached item is only tagged to "appmodelsproduct:entries" and not "appmodelscountry:entries".
Therefore when changes are made to countries table, the cached item is not invalidated.
Environment
- PHP: 8.2.3
- OS: RockyLinux 9.1
- Laravel: 10.7.1
- Model Caching: 0.13.4
Metadata
Metadata
Assignees
Labels
No labels