Closed
Description
Laravel Version
12.12.0
PHP Version
8.4.4
Database Driver & Version
MariaDB 11
Description
When using withPivot('created_at')
in a BelongsToMany
relationship, Laravel automatically includes updated_at
in the pivot table, even if withTimestamps()
was not explicitly used. This behavior forces the presence of updated_at
, preventing the usage of created_at
alone.
This implementation seems to override the expected separation of concerns:
withPivot()
should only define additional columns to retrieve within the relationship.withTimestamps()
should be responsible for explicitly managing timestamp fields (created_at
andupdated_at
).
By forcing updated_at
when only created_at
is specified, withPivot()
assumes responsibilities typically associated with withTimestamps()
, leading to unintended side effects.
Expected Behavior
Laravel should not infer updated_at
when withPivot('created_at')
is used. The inclusion of timestamp fields should depend exclusively on an explicit call to withTimestamps()
.
Possible Solution
- Adjust
withPivot()
logic so it does not automatically enforceupdated_at
. - Ensure timestamp logic remains exclusive to
withTimestamps()
, preventing unintended behavior.
Steps To Reproduce
- Define a
BelongsToMany
relationship withoutwithTimestamps()
. - Use
withPivot('created_at')
on the relationship. - Save a record and inspect the pivot table.
- Observe that
updated_at
is added automatically.
Metadata
Metadata
Assignees
Labels
No labels