0
votes

I created this module:

defmodule Discuss.Topic do
    user Discuss.Web, :model

    schema "topics" do
        field :title, :string
    end

    def changeset(struct, params \\ %{}) do
        struct
        |> cast(params, [:title])
        |> validate_required([:title])
    end
end

and I got this error when using mix phoenix.server

== Compilation error in file web/models/topic.ex ==
** (CompileError) web/models/topic.ex:2: undefined function user/2
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:229: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

Any idea of what's happening? I'm new to Phoenix and Elixir.

1
Sidenote: consider using formatter, 4 spaces for indent are not idiomatic; this makes the code way harder to read. - Aleksei Matiushkin

1 Answers

4
votes
user Discuss.Web, :model
   ^
   |
  here

should be

use Discuss.Web, :model

UPDATE

Since "web" should be a thin layer that just offloads HTTP and WebSocket, and delegate the jobs to the underlying business logic, Phoenix no longer consider models be a part of the web layer. So instead of use Discuss.Web, :model, you should use Ecto.Schema.

By the way, the web layer now contains only controllers, views, channels and the router.