Nested Embeds

Hi, I'm trying to create a resource with nested Embeds e.g.
:embed TimeRange

attributes do
attribute :start, :time
attribute :end, :time
end

:embed Checkin

attributes
attribute schedule: TimeRange
attribute ...
end

:postgres Hotel

attributes do
attribute :checkin, Checkin
...
end
:embed TimeRange

attributes do
attribute :start, :time
attribute :end, :time
end

:embed Checkin

attributes
attribute schedule: TimeRange
attribute ...
end

:postgres Hotel

attributes do
attribute :checkin, Checkin
...
end
But it seems Ecto cannot load structures like this If I understood this Issue https://github.com/elixir-ecto/ecto/issues/1256 correctly. Is this just a limitation we have to live with?
GitHub
Loading an embedded model that has a custom type field never calls ...
Given the following schema: defmodule Test.TimeEntry do use Ecto.Schema alias Timex.Ecto.DateTime schema "time_entries" do field :description, :string field :started_at, DateTime ...
4 Replies
barnabasj
barnabasjOP3y ago
This also means types like time do not work in embbeded resources
ZachDaniel
ZachDaniel3y ago
So, are you seeing issues around this with your Ash embeds? We don't use ecto's embed logic, we use regular types to back embeds:
elixir
def storage_type, do: :map
elixir
def storage_type, do: :map
And then when we load them we load the nested values. So we ought to be able to have nested embeds/support loading whatever types when using Ash embedded resources.
barnabasj
barnabasjOP3y ago
I used ecto directly to bulk insert the values, but used the regular Ash Api to read the values and I got an ecto issue. Knowing that it should be possible, I'll try again and, see if I can figure out what the problem is.
ZachDaniel
ZachDaniel3y ago
Will close this for now, but feel free to reopen if you determine that its definitely an Ash issue.

Did you find this page helpful?