我几乎遵循我们在生成的控制器中看到的模式。变更集说它有效,但是当我更新用户模型时没有更新。这个角色仍然没有。
> alias Faq.Repo
> user = Repo.get!(User, 1)
> changeset = User.changeset(user, %{role: 'admin'})
#Ecto.Changeset<action: nil, changes: %{}, errors: [], data: #Faq.User<>,
valid?: true>
> Repo.update(changeset)
{:ok,
%Faq.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
current_sign_in_at: #Ecto.DateTime<2016-12-02 03:54:54>,
current_sign_in_ip: "{127, 0, 0, 1}", email: "gary.haran@gmail.com", id: 1,
inserted_at: #Ecto.DateTime<2016-12-01 04:18:48>,
last_sign_in_at: #Ecto.DateTime<2016-12-01 04:55:51>,
last_sign_in_ip: "{127, 0, 0, 1}", name: "Gary Haran", password: nil,
password_confirmation: nil,
password_hash: "$2b$12$K603vGmolll/RtaXTrtcsusHbIsXi4IqB9yM9Ph65T3Cqlh/J5UbG",
reset_password_sent_at: nil, reset_password_token: nil,
role: nil,
sign_in_count: 5,
unlock_token: nil,
updated_at: #Ecto.DateTime<2016-12-02 03:54:54>}}
我错过了什么?
/ edit这是我的变更集方法:
def changeset(model, params \\ %{}) do
model
|> cast(params, [:name, :email] ++ coherence_fields)
|> validate_required([:name, :email])
|> validate_format(:email, ~r/@/)
|> unique_constraint(:email)
|> validate_coherence(params)
end