Today I Learned

A Hashrocket project

Named bindings in Ecto (vs positional bindings)

Positional bindings in Ecto are meant to confuse when buildings large queries across several different functions.

query = Thing
|> join(:inner, [t], x in X, on: t.x_id =
|> join(:inner, [_, x], y in Y, on: x.y_id =

Using that query in another function might look like this:

|> where([_, x, _], x.type == "Articulated")

But what if the positions change? How am I supposed to know which positions are which when I’m adding to this query out of context?

Named bindings help tremendously here (note the :as option):

query = Thing
|> join(:inner, [t], x in X, as: :x, on: t.x_id =
|> join(:inner, [_, x], y in Y, as: :y, on: x.y_id =

Now I can refer to these things without knowing the position. If the position changes it’s all good the additive where statement does not have to change:

|> where([y: y, x: x], x.type == "Articulated", y.feel == "Good")
Looking for help? Elixir is quickly gaining momentum for web applications that need concurrency, performance, and the ability to connect to many different clients. The developers at Hashrocket are learning along with the rest of the development community that Elixir and Phoenix are viable Rails alternatives for the right application. Check out the source code for Today I Learned, written in Elixir, and contact us if you need help with your Elixir project.