Skip to content

Fix #9 after_created hook ordering - #308

Merged
techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x
Sep 9, 2026
Merged

Fix #9 after_created hook ordering#308
techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x

Conversation

@techmahedy

Copy link
Copy Markdown
Member

Change

Updated the insert path in InteractsWithModelQueryProcessing.php so that the model's primary key is assigned before fireAfterHooks('created') is executed, rather than three lines afterward.

As a result, after_created hooks now receive a fully initialized model, and calls such as getKey() or $model->id correctly return the newly created record's primary key instead of null.

Tests

Extended MockHook to capture the result of getKey() from inside the hook callback.

Strengthened testAfterCreatedHook to verify that:

  • The key available inside the created hook is not null.
  • The captured key matches the model's actual primary key.

The regression test was verified by temporarily reverting the fix and confirming that the test fails with:

Failed asserting that null is not null

The test was then re-run with the fix in place and passes successfully.

@techmahedy techmahedy added the bug Something isn't working label Sep 9, 2026
@techmahedy
techmahedy merged commit ee34715 into doppar:4.x Sep 9, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant