0
콘솔의 레코드 값을 업데이트하려고합니다. ies -S mix
.Phoenix : 외래 키의 변경 사항을 고려하지 않습니다.
iex> video = Repo.one(from v in Video, limit: 1)
%Rumbl.Video{...}
동영상의 제목을 변경하면 모든 것이 제대로 작동하는 것 같습니다.
iex> changeset = Video.changeset(video, %{category_id: 3})
#Ecto.Changeset<action: nil, changes: %{},
errors: [], data: #Rumbl.Video<>, valid?: true>
무엇을 어떻게해야이 외래 키에 변경 사항이 accoung으로 수행 할 수있는 위해 :
iex> changeset = Video.changeset(video, %{title: "some title"})
#Ecto.Changeset<action: nil, changes: %{title: "some title"},
errors: [], data: #Rumbl.Video<>, valid?: true>
그러나 외부 키를 변경 효과가 없습니다 것 같다?
여기 모델
defmodule Rumbl.Video do
use Rumbl.Web, :model
schema "videos" do
field :url, :string
field :title, :string
field :description, :string
belongs_to :user, Rumbl.User, foreign_key: :user_id
belongs_to :category, Rumbl.Category, foreign_key: :category_id
timestamps()
end
@required_fields ~w(url title description)
@optional_fields ~w(category_id)
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, @required_fields, @optional_fields)
|> validate_required([:url, :title, :description])
|> assoc_constraint(:category)
end
끝 체외 2.2, the fourth argument to cast
is opts에서