Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 762 Bytes

README.md

File metadata and controls

36 lines (28 loc) · 762 Bytes

EctoUnionExample

  • Start up a standard postgres container
  • Run mix ecto.setup
  • Start a server iex -S mix phx.server
  • Insert some data:
alias EctoUnionExample.Notes.Note
alias EctoUnionExample.Notes.{Personal, Work}

work_note_params = %{
    tag: :personal,
    text: "life is great!",
    data: %{mood: "lovely", category: "random"}
  }

{:ok, %Note{data: %Work{}}} =
  work_note_params
  |> Note.create_changeset()
  |> EctoUnionExample.Repo.insert()

personal_note_params = %{
    tag: :personal,
    text: "life is great!",
    data: %{mood: "lovely", category: "random"}
  }

{:ok, %Note{data: %Personal{}}} =
  personal_note_params
  |> Note.create_changeset()
  |> EctoUnionExample.Repo.insert()


EctoUnionExample.Repo.all(Note)