Skip to content

feat(relations): withPivotValue for belongsToMany#34

Merged
3m1n3nc3 merged 1 commit into
mainfrom
feat/belongs-to-many-with-pivot-value
Jul 9, 2026
Merged

feat(relations): withPivotValue for belongsToMany#34
3m1n3nc3 merged 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 merged commit bd2d12f into main Jul 9, 2026
12 checks passed
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