ecto_embedded_type v0.1.0 EctoEmbeddedType
Transforms an Ecto embedded schema into an Ecto.Type that maps to :map
type.
You can just use it on the same module as your schema
defmodule MySchema do
use Ecto.Schema
use EctoEmbeddedType
#... define your embedded schema
end
Or, if you want, you may define the Ecto Type in another module.
defmodule MyType do
use EctoEmbeddedType, schema: MySchema
end
Now, wherever you can use an Ecto.Type
you cn use your module, so if you used the first approach
then you can just define a field with your newly generated type:
defmodule MyOtherSchema do
use Ecto.Schema
schema "table" do
field(:name, MySchema)
end
end
And make sure your migration has type :map
.
And you can even use it as primary key if you want, just use
@primary_key {:id, MySchema, autogenerate: false}