cloedu87
How to store structs to the database using Ash Framework and custom Ash.Type's
Hi there,
I’m working with ash now a couple of weeks and I’m quite a big fan
but now I’m struggling with a - so it seems - basic usecase.
I’m using the ash framework to manage my resources in the database (postgres).
I would like to store structs which are from a foreign library, namely instances of Ash.Query, to the datasbase. like:
attributes do
attribute :query, Ash.Query
...
end
Of course using Ash.Query directly as type is not possible. My first intention was to solve this with a custom Ash.Type and use…
@impl true
def storage_type, do: :map
…to tell the data layer I would like to store it as a :map on the data layer. but this did not work.
My question is: how can I define attributes on my ash resources, which are able to store structs of foreign libraries (structs which are NOT part of my code/project) and if it is only possible over custom Ash.Type’s, how can I serialize those structs properly, so I can write and read them like regular attributes?
Thanks for any hints ![]()
Claudio
Marked As Solved
zachdaniel
Loading related data and referencing related data in filters is actually unrelated. You don’t need to load something to reference it. In the case of the map syntax, it would be %{some_stuff: %{id: %{eq: id}}}
Also Liked
zachdaniel
I would suggest using the map syntax that Ash filters support. For example:
Ash.Query.filter(%{id: %{eq: ^id}})
Then you can persist the map ![]()
cloedu87
yes, right.. will do it this way, thank you very much ![]()
and thx for the awesome framework. it’s simply great ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









