-
Notifications
You must be signed in to change notification settings - Fork 0
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
BelongsToMany Relation #31
Comments
If you want native BelongsToMany support it'd help me a lot if you could share your exact uses of the relation. The thing about BelongsToMany is that it can represent vastly different things (and the UI for each of those things would be very unique), so I want to have an idea about what people are commonly using it for. |
I see. I can think of the following use cases:
|
And I see them in two major categories
|
A feature which could be useful sometimes is the possibility to set a limit to the number of related resources. If the limit is reached, the add button became disabled. I don't know if I'm the only one who ever needed something like this. |
@roberto-mgquadro What was the use case for that? Can you give an example? I can imagine this working with HasMany too. |
The last time I needed this feature was for creating padel teams. Each team could have a maximum of 2 players (1 in case the teammate has not yet been found). Same thing for the creation of the matches, each of which could have a maximum of two challengers. |
Ah yeah that makes sense. Does Laravel let you do And if so, does it enforce it on both reads and writes or only reads? 🤔 |
As far as I know, no. For this reason, a limit at a higher level may be useful |
I know that I could have created the two players directly on the team, but it was inconvenient for me due to other features. Furthermore, this example can be adapted to cases where the maximum is not only 2 but maybe 4 or 10. |
That's a good suggestion. I guess I can add |
Additional use cases
|
One thing that is difficult to configure with HasMany/BelongsToMany in Nova are the pivot fields. Any relational component here would be improved greatly if Pivot tables / custom fields on the pivot model can be accessed and edited. |
@949mac Can you describe exactly what pains you had with it in Nova? I don't think I've used it. |
This is my use case for BelongsToMany: Simplified table structure:
My models and resources in Nova:
I'll have to be able to attach and dispaly exisitng machines to a contract with additional fields in the pivot table I am in the process to rewrite the application with Lean and the BelongsToMany relation would come very handy, or or some workaround. |
While the documentation is very clear that this is not in scope, I thought that it would still be great to open up a discussion here on the feature.
I coming from Nova and the way it was simplified was that the BelongsToMany is only available after a resource has been created/edited and you can only work on the pivot table relationship
IMO this would simplify the implementation
Thoughts and comments are welcome
The text was updated successfully, but these errors were encountered: