Quantcast
Channel: Why are pin operators necessary in Ecto queries? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Why are pin operators necessary in Ecto queries?

$
0
0

In Elixir, the pin operator is used to prevent variable rebinding. However, with regard to an Ecto query like

from u in User, where: u.username == ^username

the authors of Programming Phoenix state (in chapter 7) that

Remember, the ^ operator (called the pin operator) means we want to keep ^username the same.

But this doesn't sound right, because apparently, the comparison in the query shall not cause any rebinding of variables.

Are the authors of the book (which José Valim co-authored) mistaken? Is the pin operator in Ecto queries merely a construct of the Ecto DSL instead of a usual Elixir pin operator? Or will the query really get a chance to rebind username after the macros are expanded?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>