Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- schema "post" do
- field :name, :string
- field :description, :string
- field :inserted_at, Ecto.DateTime, default: Ecto.DateTime.local
- field :updated_at, Ecto.DateTime, default: Ecto.DateTime.local
- end
- before_insert :add_creation_timestamp
- before_update :update_updated_timestamp
- def add_creation_timestamp(changeset) do
- changes = %{changeset.changes | inserted_at: Ecto.DateTime.local, updated_at: Ecto.DateTime.local}
- %Ecto.Changeset{changeset | changes: changes}
- end
- def update_updated_timestamp(changeset) do
- changes = %{changeset.changes | updated_at: Ecto.DateTime.local}
- %Ecto.Changeset{changeset | changes: changes}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement