Ecto 模型`undefined function: `when work with from macro ***in iex***
Ecto model `undefined function: ` when working with from macro ***in iex***
我在 Ecto 项目中遇到了这个问题。 None 的查询有效。
我做了一些谷歌搜索和 github 问题搜索。很少但与我的问题无关。
这个问题是从这个问题开始的https://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702(主要与我的问题有关)
query = from u in Univer, where: u.id > 4, select: u
用 ** (RuntimeError) undefined function: u/0
炸毁。不仅是那个模型,还有其他模型。
我的部门。
{:postgrex, "~> 0.9.1"},
{:poison, "~> 1.5"},
{:httpoison, "~> 0.7.2"},
{:ecto, "~> 1.0.4"},
{:floki, "~> 0.5"}
目前所有从数据库的读取都是通过 psql
完成的。它可以完成工作但很烦人。 :)
供参考。
defmodule Univer do
use Ecto.Model
import Ecto.Query
schema "univers" do
field :ref, :integer
field :name, :string
field :legal_name, :string
field :city, :string
field :type, :string
field :address, :string
field :contacts, {:array, :string}
field :fax, :string
field :phones, {:array, :string}
field :email, :string
field :url, :string
has_many :schools, School
has_one :place, Place
timestamps
end
end
和迁移
defmodule Univer.Repo.Migrations.AddUniversTable do
use Ecto.Migration
def up do
create table(:univers) do
add :ref, :integer
add :name, :text
add :legal_name, :text
add :type, :string
add :fax, :string
add :city, :string
add :contacts, {:array, :string}
add :address, :text
add :phones, {:array, :string}
add :email, :string
add :url, :string
timestamps
end
end
def down do
drop table(:univers)
end
end
我发现问题的核心是我对函数式语言中古典语言魔法的期望。
详细:
如果您想在 IEX 控制台中测试查询 (iex -S mix
)。
您必须包括
import Ecto.Query
我将它包含在模块中,但没有包含在 IEX 控制台中。
我想这很愚蠢,但值得分享。
我在 Ecto 项目中遇到了这个问题。 None 的查询有效。 我做了一些谷歌搜索和 github 问题搜索。很少但与我的问题无关。
这个问题是从这个问题开始的https://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702(主要与我的问题有关)
query = from u in Univer, where: u.id > 4, select: u
用 ** (RuntimeError) undefined function: u/0
炸毁。不仅是那个模型,还有其他模型。
我的部门。
{:postgrex, "~> 0.9.1"},
{:poison, "~> 1.5"},
{:httpoison, "~> 0.7.2"},
{:ecto, "~> 1.0.4"},
{:floki, "~> 0.5"}
目前所有从数据库的读取都是通过 psql
完成的。它可以完成工作但很烦人。 :)
供参考。
defmodule Univer do
use Ecto.Model
import Ecto.Query
schema "univers" do
field :ref, :integer
field :name, :string
field :legal_name, :string
field :city, :string
field :type, :string
field :address, :string
field :contacts, {:array, :string}
field :fax, :string
field :phones, {:array, :string}
field :email, :string
field :url, :string
has_many :schools, School
has_one :place, Place
timestamps
end
end
和迁移
defmodule Univer.Repo.Migrations.AddUniversTable do
use Ecto.Migration
def up do
create table(:univers) do
add :ref, :integer
add :name, :text
add :legal_name, :text
add :type, :string
add :fax, :string
add :city, :string
add :contacts, {:array, :string}
add :address, :text
add :phones, {:array, :string}
add :email, :string
add :url, :string
timestamps
end
end
def down do
drop table(:univers)
end
end
我发现问题的核心是我对函数式语言中古典语言魔法的期望。
详细:
如果您想在 IEX 控制台中测试查询 (iex -S mix
)。
您必须包括
import Ecto.Query
我将它包含在模块中,但没有包含在 IEX 控制台中。 我想这很愚蠢,但值得分享。