Backend

Default value for a field in changeset (use ecto schema default)

August 10, 20181 minute

Set a default value for an ecto schema like so:

defmodule Track.Time.Log do
  use Ecto.Schema
  import Ecto.Changeset

  schema "logs" do
    # ... other fields
    field(:billable, :boolean, default: true)
  end
end
Tweet this post
© 2018 Dan Bruder