Ash FrameworkAF
Ash Framework3mo ago
5 replies
Noxis

AshJsonApi relationship fields

Hi. I’m using AshJsonApi with OpenAPI and I’m struggling to figure out how to specify which fields I would like to get from a relationship.

For example, I have a hardware resource which has a belongs_to: :system relationship with a system resource which is on a different domain, and I would like to fetch the hardware with its system with specific fields. If I use the following value for the fields parameter, the attributes in the response include the system with the default_fields defined for that resource, which is expected:

{
  "hardware": "id,created_on,system"
}


If I try to use the following value for the fields parameter so that I can specify the fields for system, I get an invalid_type error for fields[system]:

{
  "hardware": "id,created_on,system",
  "system": "id,name"
}


I tried something similar using a different relationship with a resource that was on the same domain and, while I no longer get the invalid_type error, the fields returned for the relationship are the default_fields for that resource.

Note that I've also tried using includes [:system] on the hardware resource and using the include parameter, but the data of that relationship only returns the
id
and type of the system resource, which is even less helpful. I would really appreciate an example of how to get this working correctly.

Thanks!
Was this page helpful?