How to use one Enum value for REST/GraphQL, serialized as another to the database
Hello all, I'm still new to Elixir and the Ash framework. I'm trying to create a set of values to use for both the REST and GraphQL interfaces of my API to have values spelt out such as
north, north_east, etc. spelt out. However when I read or write that field to the database, I'd like to have it serialized as string values such as N, NE, etc. Here's the code I have so far:
I've tried things like overriding Ecto.type definitions for load/1, dump/1 but it keeps failing on me when I try to load an existing database record with a direction field value of NE:
1 Reply
Solution
You can override the
cast_stored and dump_to_native callbacks on the type