从数据库加载日期/时间类型时,Ecto 将转换为 Ecto.DateTime 类型。从 JSON 字符串加载模型时如何应用相同的类型转换
defmodule Rocket.User do
use Rocket.Model
schema "users" do
field :created_at, :datetime
field :name, :string
field :email, :string
field :password, :string
field :timezone, :string
end
end
iex(40)> Poison.decode!(~s({"created_at":"2015-01-21T06:05:10.891Z"}), as: Rocket.User)
%Rocket.User{created_at: "2015-01-21T06:05:10.891Z", email: nil, id: nil,
name: nil, password: nil, timezone: nil}