Skip to content

[13.x] Fix whereAttachedTo() ignoring custom related key on BelongsToMany - #62350

Open
KalimeroMK wants to merge 1 commit into
laravel:13.xfrom
KalimeroMK:fix/where-attached-to-related-key
Open

KalimeroMK wants to merge 1 commit into
laravel:13.xfrom
KalimeroMK:fix/where-attached-to-related-key

Conversation

@KalimeroMK

Copy link
Copy Markdown
Contributor

whereBelongsTo() respects custom owner keys ($relationship->getOwnerKeyName()), whereas whereAttachedTo() always filters by $related->getKeyName() via whereKey(). When a belongsToMany or morphToMany relationship uses a custom $relatedKey (e.g. uuid), whereAttachedTo() plucks and queries the model's primary key (id) instead of the relationship's related key.

This updates whereAttachedTo() to filter by $relationship->getRelatedKeyName() when the relationship uses a custom related key.

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