Phoenix/Ecto - 未检索到 Postgres 数组列中的整数值

Phoenix/Ecto - integer values in a Postgres array column not being retrieved

正在尝试在 Phoenix 1.3.0 应用程序中使用 Ecto 2.1 为现有的一组 table 构建模式。

示例:

defmodule Book do
 use Ecto.Schema

 schema "books" do 
     field :title, :string
     field :owner_ids, {:array, :integer}
     field :borrower_ids, {:array, :integer}
     field :published, :boolean
 end
end

在控制台上,当我执行 Book |> first |> Repo.one 时,我看到 owner_ids 正确打印 ["29"],但 borrower_ids 显示“$”。使用 psql 验证 table 中该行的 borrower_ids 在 table 中确实有一个值列表,与 owner_ids 列完全一样。 table 中的所有其他列打印得很好。我在这里缺少什么吗? 更新: Rails/ActiveRecord 5.1.4 能够检索此 table 并且行很好。

'$' 是一个包含数字 36 的列表:

iex> [36]
'$'

简而言之,每次 Elixir 看到表示 ASCII 字符的整数列表时,它都会在单引号之间打印它们,因为这就是 Erlang 字符串的表示方式(也称为字符列表)。

IEx 中的 i 助手在这些情况下非常有用。当你看到一个你不明白的值时,你可以通过它来询问更多信息:

iex(2)> i '$'
Term
  '$'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent valid
  ASCII characters. Conventionally, such lists of integers are referred to
  as "charlists" (more precisely, a charlist is a list of Unicode codepoints,
  and ASCII is a subset of Unicode).
Raw representation
  [36]
Reference modules
  List