我在Ecto项目中遇到了这个问题.没有任何查询正在运行.我做了一些谷歌搜索和github问题搜索.有几个但与我的问题无关.
这个问题是从这个问题开始的https://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702(主要与我的问题有关)
query = from u in Univer, where: u.id > 4, select: u
Run Code Online (Sandbox Code Playgroud)
爆发了** (RuntimeError) undefined function: u/0.不仅是那个型号,还有其他型号.我的朋友.
{:postgrex, "~> 0.9.1"},
{:poison, "~> 1.5"},
{:httpoison, "~> 0.7.2"},
{:ecto, "~> 1.0.4"},
{:floki, "~> 0.5"}
Run Code Online (Sandbox Code Playgroud)
目前所有从db读取都是通过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
Run Code Online (Sandbox Code Playgroud)
和迁移
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
Run Code Online (Sandbox Code Playgroud)
And*_*nyy 27
我发现问题的核心是我对功能语言中古典语言魔术的期望.
详细地:
如果要在IEX控制台(iex -S mix)中测试查询.你必须包括
import Ecto.Query
Run Code Online (Sandbox Code Playgroud)
我把它包含在模块中但不包含在IEX控制台中.我想,这很愚蠢,但值得分享.
| 归档时间: |
|
| 查看次数: |
2970 次 |
| 最近记录: |