Ecto:列v0.availabilites不存在

时间:2016-03-25 15:46:33

标签: elixir phoenix-framework ecto

我的一项行动失败了

(Postgrex.Error) ERROR (undefined_column): column v0.availabilites does not exist

查看Phoenix日志,我发现生成错误的查询:

[debug] SELECT v0.id, v0.event_id, v0.availabilites, v0.inserted_at, v0.updated_at
FROM votes AS v0 WHERE (v0.event_id IN ($1)) ORDER BY v0.event_id [1] ERROR query=185.8ms

荒谬的是,提到的专栏存在!以下是psql的输出:

    Table "public.votes"
     Column     |            Type             |                     Modifiers                      
----------------+-----------------------------+----------------------------------------------------
 id             | integer                     | not null default nextval(votes_id_seq::regclass)
 availabilities | jsonb                       | 
 inserted_at    | timestamp without time zone | not null
 updated_at     | timestamp without time zone | not null
 event_id       | integer                     | 
Indexes:
    "votes_pkey" PRIMARY KEY, btree (id)
    "votes_event_id_index" btree (event_id)
Foreign-key constraints:
    "votes_event_id_fkey" FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE

如你所见,专栏就在那里!以下是两个相关模型:

defmodule LetsPlan.Vote do
  use LetsPlan.Web, :model

  schema "votes" do
    belongs_to :event, LetsPlan.Event
    embeds_many :availabilites, LetsPlan.Availability

    timestamps
  end

  @required_fields ~w(availabilites event_id)
  @optional_fields ~w()

  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
  end
end

defmodule LetsPlan.Availability do
  use LetsPlan.Web, :model

  embedded_schema do
    field :from, Ecto.Date
    field :to, Ecto.Date
  end
end

1 个答案:

答案 0 :(得分:4)

你有一个错字:

embeds_many :availabilites, LetsPlan.Availability

应该是:

embeds_many :availabilities, LetsPlan.Availability