I am trying to do the following,
defmodule Command do
defmacro __using__(opts \\ [], do: block) do
unless Keyword.has_key?(opts, :aggregate_identifier) do
raise ArgumentError, "Missing :aggregate_identifier key"
end
aggregate_identifier = Keyword.fetch!(opts, :aggregate_identifier)
quote do
use Ecto.Schema
@primary_key { @aggregate_identifier_key, :binary_id, autogenerate:
true }
@derive Jason.Encoder
embedded_schema unquote(block)
end
end
end
Just so I can do something like,
defmodule CreateRecurringTransfer do
use Command, [aggregate_identifier: :id] do
field(:dtstart, :naive_datetime)
field(:dtend, :naive_datetime)
embeds_one(:amount, PositiveAmount)
embeds_one(:rrule, Rrule)
embeds_one(:owned_by, CustomerIdentity)
embeds_one(:from_account, TransferAccount)
embeds_one(:to_account, TransferAccount)
end
end
But I get `** (CompileError) iex:3: undefined function use/3` which I
assume what I am trying to do is not supported.
I am curious to understand why it doesn't work (beside maybe not being
supported), and what would be the problem by trying to support it
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/81497f12-c0ab-4cfc-b747-c7d3465b55b3n%40googlegroups.com.