Skip to content

Hotfix/custom timestamps and builder soft deletes - #14

Merged
tabennett merged 6 commits into
masterfrom
hotfix/custom-timestamps-and-builder-soft-deletes
Nov 15, 2026
Merged

tabennett merged 6 commits into
masterfrom
hotfix/custom-timestamps-and-builder-soft-deletes

Conversation

@tabennett

Copy link
Copy Markdown
Contributor

No description provided.

storeEntity() excluded the timestamp columns from an update with self::, so a
mapper that overrides CREATED_AT and UPDATED_AT had its created column included
in every UPDATE with the entity's value, wiping the stored creation time when
the entity didn't carry it. Exclude them with static:: like the rest of the
method. Mappers with the default column names are unaffected.

Add a fixture table, entity and mapper with custom timestamp columns, and
tests for insert, update, and the UPDATE statement.
SoftDeletingScope called getDeletedAtColumn() on the mapper, which has never
existed (the SoftDeletes trait defines getDeletedAtColumnName()), so
where(...)->delete() and restore() on the builder always threw. The scope was
ported from Eloquent, whose trait uses the other name.

Also update through toBase() instead of the builder's __call fallback, which ran
the raw query: it ignored global scopes, so rows that were already soft deleted
would have been stamped again, and it returned the builder instead of the number
of rows affected. Eloquent's scope relies on a real Builder::update() that does
this; Holloway has none.

Add tests for bulk soft delete, restore, the returned row counts, rows that are
already deleted, and force delete.
Replace the warnings that these were unreliable. Note that they update in a
single query, return the affected row count, don't fire persistence events,
and stamp deleted_at with Carbon::now() rather than the mapper's currentTime().
Typing the relationship properties in 1e0f8d5 turned `protected $map;` into
`protected ?Closure $map;`. An untyped property defaults to null, but a typed
one is left uninitialized, so getMap() on a custom relationship that was given
an entity class threw an Error instead of returning null, and getData() threw
before the relationship had been loaded. The loader never calls either for
those relationships, which is why nothing noticed.

Default $map and $data on Custom and $data on BaseRelationship to null, the
way $entityName already is.

Also drop the docblock on Custom::__construct, which described $query as a
QueryBuilder where it is a Closure, and the import it was the only user of.
The parameter is typed Scope|string, so once the string case is handled
anything left is a Scope and the InvalidArgumentException for anything else
could never be thrown.
Add tests for the builder's finders, or-where grouping inside global scopes,
local scopes, simple and empty pagination, chunk and chunkById, macros and
nested where closures; the Holloway registry; soft deleting entities with
their events, force removal and restoring many at once; global scope
registration and removal; custom relationships defined with callables and
closures; mapper configuration accessors and non-incrementing inserts; the
factory and the service provider. Line coverage goes from 67% to 98.5%.

Also document that a bulk delete through a query fires no removal events.

Fix the custom relationship in the PackMapper fixture, which assigned
`$pack->id = $collar->pack_id` instead of comparing, so every pack was given
every collar. The test that loads it onto many entities only checked the type
of each collar, so assert how many each pack gets.
@tabennett
tabennett merged commit c786f72 into master Nov 15, 2026
24 checks passed
@tabennett
tabennett deleted the hotfix/custom-timestamps-and-builder-soft-deletes branch November 15, 2026 06:50
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

Successfully merging this pull request may close these issues.

1 participant