reason in updated() event

Open
#77 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
laravel, php
Domain
backend

Research direction

Start with the updated(Foo $foo) event and the currentVersion() call shown in the issue. Reproduce the timing that returns the previous version, then trace how the current version and reason are loaded around the update event. Done means the event reliably exposes the current version's reason rather than a cached or previous version.

Written by the indexing model from the issue text.

Description

I am using the reason inside an updated event. It seems like reason is reset before this event is triggered, So I figured I just fetch it from the current version, but for some (likely stupid) reason, I sometimes then get the previous and not the current version. I assume there is some caching going on, so I wonder how I can reliably ensure I get the actual current version and not some cached instance that is no longer valid after the update?

public function updated(Foo $foo)
{
    $version = $foo->currentVersion();
    $action = $version->reason;
Dominant language
PHP
Stars
787
Forks
99
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mpociot/versionable

All issues in mpociot/versionable

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.