Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

withPivot('created_at') Unexpectedly Forces updated_at in Pivot Tables #55919

Copy link
Copy link
Closed
@jjdevzinho

Description

@jjdevzinho
Issue body actions

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 and updated_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 enforce updated_at.
  • Ensure timestamp logic remains exclusive to withTimestamps(), preventing unintended behavior.

Steps To Reproduce

  1. Define a BelongsToMany relationship without withTimestamps().
  2. Use withPivot('created_at') on the relationship.
  3. Save a record and inspect the pivot table.
  4. Observe that updated_at is added automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.