Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. schema "post" do
  2. field :name, :string
  3. field :description, :string
  4. field :inserted_at, Ecto.DateTime, default: Ecto.DateTime.local
  5. field :updated_at, Ecto.DateTime, default: Ecto.DateTime.local
  6. end
  7.  
  8. before_insert :add_creation_timestamp
  9. before_update :update_updated_timestamp
  10.  
  11. def add_creation_timestamp(changeset) do
  12. changes = %{changeset.changes | inserted_at: Ecto.DateTime.local, updated_at: Ecto.DateTime.local}
  13. %Ecto.Changeset{changeset | changes: changes}
  14. end
  15.  
  16. def update_updated_timestamp(changeset) do
  17. changes = %{changeset.changes | updated_at: Ecto.DateTime.local}
  18. %Ecto.Changeset{changeset | changes: changes}
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement