Skip to content

kyleVsteger/ecto_union_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages