-
-
Notifications
You must be signed in to change notification settings - Fork 28
How to sync multiple relations? #95
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
Comments
Hello @Stiropor, I understand your problem, this might be a good option to be able to provide multiple keys as you are giving me the point, I'll put this as a new feature 😄 While you wait for this to be done, what you can simply do is remove the "without_detaching" from the first argument, this will detach all former ids do you see what I mean ? |
This works, yes. The problem with this is when all tags are deleted, I cannot send empty [] and ask for sync. I'd always need to know which tags there were before. |
I'm not sure I understand your problem, could you please precise it ? |
Certainly. I'm using this to handle belongsToMany relation, in this case article with tags. When adding tags, there is no problem. When modifying them I can also use sync (without without_detaching on first one it works). But when editing an article and all tags are removed there is nothing to send to use sync as I'd normally use it in Laravel to sync relations. The only way would be to somehow remember original attributes of article, which is kinda unusual and not useful otherwise. Doing a sync with |
This is lovely but I'm yet to understand what you are doing |
Description
First of all - great package! Works really nice.
I do have a question - mutation endpoint supports also sync, but somehow I cannot figure out how to make sync for multiple related resources. For example an article has a BelongsToMany relation with tags. When tags change on an article - how do I send only new ids (keys) of tags to sync, as I would do with ->sync() method in Laravel?
This is what I'm using for now:
If I don't send
without_detaching
only last tag is then attached to articles. If I addwithout_detaching
then new ones are added but old ones (id: 1) are still there.It'd be maybe cool to either use
keys
(array) attribute, to sync multiple related models or just makingkey
attribute also being allowed as an array, but this could of course make things more complex I suppose.Any ideas?
The text was updated successfully, but these errors were encountered: