Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UndefinedFunctionError - iex aliasing in phoenix / ecto

when i launch

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 ProjectName, it works:

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

How can I avoid having to prefix my calls with my Project Name in iex?

like image 355
Doug Avatar asked Jun 02 '16 16:06

Doug


1 Answers

If you add code to the file .iex.exs, it'll get executed whenever you launch iex in that directory. So if you just add this to your .iex.exs:

alias ProjectName.{Repo, MyModel}

you'll be able to access ProjectName.Repo as Repo and ProjectName.MyModel as MyModel.

like image 164
Dogbert Avatar answered Nov 04 '22 21:11

Dogbert