-
Notifications
You must be signed in to change notification settings - Fork 93
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
Is it possible to "create" associated resources at the same time as the main resource? #270
Comments
Hi, this should work, however the example is very basic and I haven't implemented that in the code. I will try to add this feature in the example and extend the example tests to verify that this really works when implemented. |
Hey @wwwdata I'd appreciate that. Especially since the alternative is to create one resource then make individual api calls for each relation. I think I was very diligent in making sure I was doing everything correctly, so I'm looking forward to the results of your test. |
I found the problem in our examples. As expected I just made a mistake. When reference IDs are in the payload, the |
Ok I will make that change. But still, I noted that in the updated example the ID is |
ah, now I understand what you mean. You want to create the user and new referenced data in one request. So one user and 2 chocolate datasets. Hmm. Are you trying to send the chocolates in the I think there also is no official example in the jsonapi.org spec, right? They only have examples with reference IDs. |
That is precisely what I'm trying to do. |
Yes, the chocolates are in the |
api2go cannot do that for now. Unmarshaling is only working with IDs. One other problem we have is how we manage the IDs of the new chocolates. The We should look a bit more into the jsonapi specification if anything is specified how to do this properly or if something is in the works that we can early adopt. Did you find anything in their documentation how to correctly send payload to create relationships along the the main object @carlisia ? |
Hm. This is interesting. Looking now I see that they specify how to do a post with an association if it is something like, posting a Nothing yet on how to do it the other way around. |
This feature seems to be planned for 1.1 http://discuss.jsonapi.org/t/json-api-weekly-meeting-june-22nd-2015/23 but we only support 1.0 at the moment.. |
This seems like a common problem. I found several folks complaining about the lack of atomicity in create calls to JSON API. My solution was the same as @carlisia, I'd like to post the main object, and it's related object in the included array. Like @carlisia i think the simple solution would be to include the entire object (in raw format) as part of the request object (or the object, object) so that I could at least implement this myself if I wanted to. |
It seems that this is the issue where this feature is being discussed: json-api/json-api#1089 |
Wondering if there has been some update with resolving this issue? |
unfortunately not, you should watch this issue json-api/json-api#1089 |
too bad, thanks though |
I'm hitting a post endpoint for a resource that has a relation. To use your example, it would be much like posting a user that has data for two chocolates.
I notice that the resource
user
gets created, but not the associatedchocolates
.I am now doubting that this is even possible and would love it if you could confirm one way or the other. When I look at your example for a post, I see that there is no payload for the association:
https://github.com/manyminds/api2go/blob/master/examples/crud_example_test.go#L60
On my end, I've debugged enough to see that when
SetToManyReferenceIDs
is called, theIDs
that are passed in are correct in number (there are two associations and there are twoIDs
), but they are set to zero. This makes sense because at this pointcreate
hasn't been called yet.When
create
does get called, I inspect theobj
and the array for the association (which would bechocolates
) is empty. If it wasn't empty I could grab the data and save it to the db.I have implemented all the interfaces to make associations work, at least I'm pretty sure I have.
The text was updated successfully, but these errors were encountered: