DEV Community

Sushant Bajracharya
Sushant Bajracharya

Posted on

2 2

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay