Benjamin Milde

Designer, Frontend-Developer & Photographer

Read this first

Child Specs in Elixir

Child specs are often confusing for people trying to convert the old Supervisor.Spec based syntax to the newer child spec based syntax, people trying to integrate with erlang libraries or because they added more parameters to their start_link functions and now wonder why it fails when trying to supervise the process.

Child spec map

To start, it’s important to know what a child spec is. It’s a map of data, which is used by supervisors to determine how they should start and interact with a certain supervised child. The format is documented in the Supervisor docs for elixir as well as the :supervisor docs for erlang, therefore I’ll keep my explanations short. There are 6 keys: :id, :start, :restart, :shutdown, :type and :modules. Besides :id and :start the keys are optional with defaults.

The child spec for an run-of-the-mill GenServer essentially looks like this:

%{
    id: Stack,
...

Continue reading →


Ecto: When to cast

People starting out with ecto are often confused by all the methods of getting changes applied to a changeset and therefore the database. Especially the options around assocications are often problematic. To bring some clarity into the matter one first needs to understand a thing about the architecture ecto and changesets operate under.

There are three conceptional types of data ecto deals with. There’s user input, which is often provided in a subset of data types of what a schema is meant to carry. E.g. in a web context forms often submit data with text values only. JSON serialize data might know a few more data types, but is still quite limited. Then there’s the actual values one want’s to have have at runtime in schemas – your field :some_name, :date being a %Date{}. The third type is the data type the runtime data is serialized into for database storage.

Converting user input into...

Continue reading →


A case against many_to_many

On the Slack Channel for Elixir there’s often the situation of people coming from other languages/frameworks to elixir and especially ecto to ask about “How to model many-to-many relationships”.

Most of the times the usual answer comes as a surprise to people, as usage of Ecto.Schema.many_to_many is almost actively discouraged. I’ll try to bring some insights into why this is the case and what’s the better alternative.

many_to_many in ecto

For quite some time ecto didn’t even come with many_to_many relationships and people instead modeled them explicitly using plain belongs_to/has_many relationships on all tables involved. But due to popular demand explicit support was eventually added. (1)

There’s one caveat though. It was added with the intent of hiding away the implementation detail of needing a join-table to create the relationship between the two many-to-many schemas. Because...

Continue reading →


Are elixir deployments really that hard?

Thoughts like this are not really rare for people new to elixir. And they’re not totally wrong in their assessment either. Doing such a comparison however expects that a similar level of “just handle this for me” is actually possible for elixir tools to provide and if so that it’s a good idea to do so. This is an...

Continue reading →