/ecto_poly

Polymorphic embeds with ecto

Primary LanguageElixir

EctoPoly

TODO: Add description

Installation

If available in Hex, the package can be installed by adding ecto_poly to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_poly, github: "nerdyworm/ecto_poly"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ecto_poly.

defmodule Example do
  use Ecto.Schema
  import Ecto.Changeset
  import EctoPoly

  schema "examples" do
    field(:name, :string)
    embed_poly(:data)
  end

  @doc false
  def changeset(config, attrs) do
    config
    |> cast(attrs, [:name])
    |> cast_poly(:data)
  end
end