Skip to content

feat(relations): withPivotValue for belongsToMany#33

Closed
3m1n3nc3 wants to merge 1 commit into
mainfrom
feat/belongs-to-many-with-pivot-value
Closed

feat(relations): withPivotValue for belongsToMany#33
3m1n3nc3 wants to merge 1 commit into
mainfrom
feat/belongs-to-many-with-pivot-value

Conversation

@3m1n3nc3

@3m1n3nc3 3m1n3nc3 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Adds withPivotValue(column, value) and withPivotValue({ column: value }) to belongsToMany relationships. It:

  • constrains the relationship to pivot rows where the column equals the value (via wherePivot, so it applies to reads, eager loads, and mutation scoping), and
  • records the value as the default for that column when a new pivot row is created through the relationship (attach/create/save/sync). Explicit pivot attributes still override it, and the foreign/related keys always win.

Tests: default on create/attach, object form, attribute override, and the
read-side filter. Docs: pivot helpers section.

Adds withPivotValue(column, value) and withPivotValue({ column: value })
to belongsToMany relationships. It:

- constrains the relationship to pivot rows where the column equals the value
  (via wherePivot, so it applies to reads, eager loads, and mutation scoping),
  and
- records the value as the default for that column when a new pivot row is
  created through the relationship (attach/create/save/sync). Explicit pivot
  attributes still override it, and the foreign/related keys always win.

Tests: default on create/attach, object form, attribute override, and the
read-side filter. Docs: pivot helpers section.
@3m1n3nc3 3m1n3nc3 closed this Jul 9, 2026
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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