mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.22k stars 212 forks source link

Observer for Pivot Model not firing #467

Open Restingo opened 1 month ago

Restingo commented 1 month ago

Describe the bug I've got two models, lets name them Company and Contact. I've also got a pivot model CompanyContact. For the pivot model I've created an observer that is called CompanyContactObserver.

Now if model caching is enabled via .env file the CompanyContactObserver doesn't fire.

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

$company->contacts()->sync($contacts);

Stack Trace None.

Environment

Additional context If model caching is disabled the observer fires instantly.

mikebronner commented 1 month ago

@Restingo thank you for reporting this. If you can provide a PR with a failing test, or even the fix, that would help out tremendously.

Restingo commented 1 month ago

@mikebronner thanks for your fast response. Would it also be sufficient to commit the models and some test controller? I don't know in which file I need to put the test case :(

mikebronner commented 1 month ago

@Restingo Hey, in that case I would recommend just setting up a test repo that demonstrates the problem (comment the code where the problem happens). That will help write the test.