UndefinedFunctionError - iex aliasing in phoenix / ecto

when i run

iex -S mix phoenix.server

I would like to be able to run commands like:

iex(1) > Repo.all(MyModel)

However, this gives me this error:

(UndefinedFunctionError) undefined function: Repo.all/1 (module Repo is not available)

If I prefix my calls with my project name, it works:

iex(1) > ProjectName.Repo.all(ProjectName.MyModel)

How can I avoid the prefix of my calls with my project name in iex?

+4
source share
1 answer

If you add the code to the file .iex.exs, it will be launched at startup iexin this directory. Therefore, if you just add this to your .iex.exs:

alias ProjectName.{Repo, MyModel}

You can access ProjectName.Repohow Repoand ProjectName.MyModelhow MyModel.

+7
source

All Articles