Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flush morphToMany not working #82

Open
hen3b182 opened this issue Jul 8, 2020 · 3 comments
Open

flush morphToMany not working #82

hen3b182 opened this issue Jul 8, 2020 · 3 comments

Comments

@hen3b182
Copy link

hen3b182 commented Jul 8, 2020

Project.php

class Project extends Model
{	
    use Rememberable;

    public $rememberCacheTag = 'project_queries';
    public $rememberFor = 60*60*24;
	
    public function users()
    {
        return $this->morphToMany(User::class, 'model','model_has_users');
    }

User.php

class User extends Authenticatable
    {
        use Rememberable;
    
        public $rememberCacheTag = 'user_queries';
        public $rememberFor = 60*60*24;
        
    public function projects()
    {
        return $this->hasMany(Project::class);
    }

Now this works:

Cache::flush();

And this does not:

Project::flushCache('project_queries');

Project::find(1)->name (refreshed)
Project::find(1)->users (not refreshed)

help!?

@dwightwatson
Copy link
Owner

Wouldn't you want to flush the user_queries cache in this instance?

There's some known issues regarding caching with morph relationships. Happy to review any code that seeks to resolve the problems.

@hen3b182
Copy link
Author

hen3b182 commented Jul 9, 2020

Wouldn't you want to flush the user_queries cache in this instance?

There's some known issues regarding caching with morph relationships. Happy to review any code that seeks to resolve the problems.

Do I have to flush both cache tags in this case? And all other morph relations?

@dwightwatson
Copy link
Owner

Yeah, I'd assume so. But there are a few open issues around morphing relationships, so no guarantees this will work as you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants