Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Grabbing a list of data

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content