sezaru
Does Ash supports polymorphic embedded resources?
The title says it all, is it possible to create more than one embedded resource and use them both as a single attribute in a third resource?
I was thinking about something similar to what this library does for ecto: Polymorphic embeds for Ecto — Polymorphic Embed v5.0.6
Marked As Solved
zachdaniel
Creator of Ash
Yes ![]()
defmodule YourEmbed do
...
end
defmodule YourOtherEmbed do
...
end
attribute :one_or_the_other, :union do
constraints types: [
one: [type: YourEmbed],
other: [type: YourOtherEmbed]
]
end
You can also extract that out into a NewType
defmodule OneOrTheOther do
use Ash.Type.NewType, subtype_of: :union, constraints: [
types: [
one: [type: YourEmbed],
other: [type: YourOtherEmbed]
]
]
end
Then you can use the type like so:
attribute :one_or_the_other, OneOrTheOther
Check the docs for unions, as you may want some of the additional tools around it, like tag and tag_value to configure a type field and the value it should equal for it to be considered one type or the other.
The union type can also be used with primitives.
8
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Hello, how can I check the Phoenix version ?
Thanks !
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









