# AshJsonApi - includes & default\_fields

**URL:** <https://forum.elixirforum.com/t/ashjsonapi-includes-default-fields/67830>\
**Category:** Questions\
**Tags:** ash, ash-json-api\
**Created:** [December 2, 2024, 10:58pm UTC](https://forum.elixirforum.com/t/ashjsonapi-includes-default-fields/67830 "2024-12-02T22:58:44Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![MartinVolerich](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/martinvolerich/32/7479_2.png) [@MartinVolerich](https://forum.elixirforum.com/u/MartinVolerich)\
**Post date:** [December 4, 2024, 3:35pm UTC](https://forum.elixirforum.com/t/ashjsonapi-includes-default-fields/67830/5 "2024-12-04T15:35:23Z")

</div>

I found where the problem lies (for this case).

The situation is that I am including a related resource (in this case “Product”) in the GET and relying on the public of default\_fields set for that resource.

If I set the default\_fields for the main “base” resource (in my case “Survey”) in the base\_route, then the included resource isn’t queried for its fields.

However if I set the default\_fields for the main “base” resource in the resource module itself (inside the json\_api block), then the other related resources is asked for it’s fields.

The problem is due to the logic at line 675 of the AshJsonApi.Serializer where fields is determined to be one of three lists.

fields =  
Map.get(request.fields, resource) || Map.get(request.route, :default\_fields) ||  
default\_attributes(resource)

If I manually swap the second and third parts then the default\_fields on the route itself isn’t used when there are default fields set for the resource. And of course default\_attributes has logic that will look to the explicit default\_fields or the public attributes.

So a workaround is to just set the fields to be used as defaults in the resource and not in the route (in this case), but I’d be interested to hear what approach makes most sense.

FWIW, I’ll also post this in the issues list for the project.

Thanks  
Martin

---

_[View the full topic](https://forum.elixirforum.com/t/ashjsonapi-includes-default-fields/67830)._
