April 2018
Beginner to intermediate
406 pages
9h 33m
English
We'll build a function that can provide a simple interface to get the data out of the system and to our controllers. So what do we want here? We want a simple function that is going to return an array of data (in our case, Polls). Of course, we'll also want to preload the Options for those Polls as well. The good news is that writing functions for our interfaces is just as simple as writing functions in Elixir! Let's take a look at our first example:
def list_polls do Repo.all(Poll) |> Repo.preload(:options) end
All we've done here is written a single line of code, and yet this is also the code that will give us access to our Poll and Option data! Now, when we want a list of Polls, we don't need to think about having ...