DEV Community

Sushant Bajracharya
Sushant Bajracharya

Posted on

alias in elixir

This post will not explain about alias , rather I would like to share a piece of code that caught me off guard.

alias Rumbl.Accounts # context
alias Accounts.User # schema

def first_name(%User{name: name}), do: name
Enter fullscreen mode Exit fullscreen mode

If I compile it, it would give me compilation error Rumbl.Accounts.User__struct__/0 is undefined.

It's pretty obvious why, looking at the code now. Since the Rumbl.Accounts is already aliased, the Accounts.User assumed Accounts to be Rumbl.Accounts.

Just updating their position would fix it

Top comments (0)