Skip to content

Preserve membership filters on many-to-many writes - #389

Open
shuvroroy wants to merge 3 commits into
laravel:0.xfrom
shuvroroy:fix/filtered-many-to-many-detach
Open

shuvroroy wants to merge 3 commits into
laravel:0.xfrom
shuvroroy:fix/filtered-many-to-many-detach

Conversation

@shuvroroy

@shuvroroy shuvroroy commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

When a user has both an admin membership and a member membership for the same role, user.admin_roles().detach(role_id) deletes both rows on 0.x. The relation filter selects the role ID correctly, but the delete uses only the user and role IDs.

This change applies the relation filter to each join row during detach, sync, toggle, and join-row updates. Filtered bulk writes bind only linked IDs and split oversized writes inside a transaction. On MySQL, a materialized subquery lets a filter read the membership table during the write.

Tests

All 37 model-filter tests passed across SQLite, MySQL, MariaDB, and PostgreSQL. Regression coverage includes duplicate memberships, 40,000 requested IDs with one match, 32,765 matching memberships, rollback on a late update conflict, and a filter that counts memberships on the same table.

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