AshJsonApi + Managed Relationships
Are there any examples of AshJsonApi, the docs seem outdated. Im trying to get managed relationships to work through a 'parent' resource.
14 Replies
This is my current setup for a "Location" resource and an "Area" managed relationship:
When trying to get
http://localhost:4000/api/locations/55b9cd3c-8a83-431e-b580-98365bc2b5ab/relationships/areas
, I get a 500
This is the
Area
resource
Oh, okay that looks like a bug that may actually have been fixed already
are you on the latest version of
ash_json_api
?
If so, can you try pointing at main? github: "ash-project/ash_json_api", ref: "main"
?@Zach Daniel That works! Although it does not return any of its fields, just an id and type
🤔
oh, yeah that is correct
relationship/2
creates an endpoint designed to do that
if you want an endpoint that returns the full related entities thats when you use related/2
which is typically the difference between /thing/:id/relationships/related
and /thing/:id/related
https://jsonapi.org/format/#fetching-relationshipshm, tried
http://localhost:4000/api/locations/55b9cd3c-8a83-431e-b580-98365bc2b5ab/areas
but got a 404?
sorry, actually worked!Not getting related links for included relationships though, is that right?

looks like a
get_related
route needs to be marked as primary to show up there
So if you set the get_related
to primary? true
then it should appear in the links
its been a long time since I made that choice, but I imagine it was to solve for cases where there were multiple endpoints to get the same relationship
That could probably be improved 🙂That worked too!
Im trying to patch a managed resource through the main one, eg:
http://localhost:4000/api/locations/55b9cd3c-8a83-431e-b580-98365bc2b5ab
Curl eg:
Any idea how that works? I have this on the main resource
You provide it as an attribute in that case
the map of data to be passed into the managed relationship I mean
we pull arguments and attributes out of the
attributes
field (because JSON:API
doesn't give us anywhere else to accept input AFAIK)
released 0.32.1
so you don't need to be on a GH branch 🙂Looking at the spec for jsonapi here:
https://jsonapi.org/format/#crud-updating-resource-relationships
Looks like you can update from passing it as a relationship on patch?
actually yeah it looks like we will search for arguments meant to manage relationships
ah, thats right, its configured
You say which arguments are edited in the relationships