Ho riscontrato questo problema con il progetto Ecto. Nessuna delle query funziona. Ho fatto un bel po 'di ricerche su googling e github. Ce ne sono pochi ma non sono collegati al mio problema.Funzione ecto `funzione non definita:` quando si lavora con da macro *** in iex ***
Questa domanda è stata lanciata da questo https://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702 (per lo più legate al mio problema)
query = from u in Univer, where: u.id > 4, select: u
fa saltare in aria con ** (RuntimeError) undefined function: u/0
. Non solo quel modello ma anche altri modelli. I miei deps.
{:postgrex, "~> 0.9.1"},
{:poison, "~> 1.5"},
{:httpoison, "~> 0.7.2"},
{:ecto, "~> 1.0.4"},
{:floki, "~> 0.5"}
Attualmente tutta la lettura da db avviene tramite psql
. Fa il lavoro ma fastidioso. :)
Per il riferimento.
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
e la migrazione
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
È sicuramente una trappola comune! –
C'è un modo semplice per precaricare alcune cose del genere? – brightball
@aramisbear È possibile aggiungere un file '.iex.exs' nella radice del progetto contenente' import Ecto.Query'. Quindi eseguirà quel comando quando aprirai IEX. –