Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change plural to singular in getInverseRelationship in HasQuery #14145

Open
wants to merge 5 commits into
base: 3.x
Choose a base branch
from

Conversation

pelmered
Copy link

@pelmered pelmered commented Sep 4, 2024

Description

This fixes #14090 where the inverse of a one to many-relationship in the AssociateAction uses plural for the relation name and subsequently also the foreign key. This is according to the Laravel convention.

Visual changes

N/a

Functional changes

  • Changes from the inverse relationship name from plural to singular in for example AssociateAction

Looking at the Laravel documentation as an example: https://laravel.com/docs/11.x/eloquent-relationships#one-to-many-inverse.
On the post resource we add a relationship manager for comments, and in the relationship manager we add an AssociateAction to associate comments with the current post.
The current code would look for the inverse relationship with the name posts (plural) instead of post (singular).

This is only tested for one to many-relationships and many to many-relationships. The $relationship instanceof HasMany if-statement probably needs to be updated to cover more cases.

@zepfietje zepfietje added this to the v3 milestone Sep 5, 2024
@zepfietje zepfietje added the bug Something isn't working label Sep 5, 2024
@danharrin
Copy link
Member

Hi @pelmered are you still planning to work on this?

@pelmered
Copy link
Author

Hi @pelmered are you still planning to work on this?

Sorry, I have been really busy the last few weeks. And I will probably be busy for the next few weeks as well.
I would be happy if someone took over. Otherwise I can work on it when I have a bit less things on my table, but that will probably not be until mid October.

@zepfietje
Copy link
Member

No worries, @pelmered!
I just took over this PR, implementing the comments by @danharrin.
Tested on a real project and it does fix the bug.

Ready for merge! 😊🚀

@pelmered
Copy link
Author

No worries, @pelmered! I just took over this PR, implementing the comments by @danharrin. Tested on a real project and it does fix the bug.

Ready for merge! 😊🚀

Great! Thank you! 😁🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

AssociateAction derives wrong inverse relationship name
3 participants