April 2019
Beginner to intermediate
244 pages
6h 34m
English
One of the most useful things you can do is add aliases for the modules you work with often. You’ll most likely want to start with Repo and most (if not all) of your schema modules. For the MusicDB app, you might do the following:
| | alias MusicDB.{ |
| | Repo, |
| | Artist, |
| | Album, |
| | Track, |
| | Genre, |
| | Log |
| | } |
This one addition means that instead of typing this:
album = MusicDB.Repo.get(MusicDB.Album, 1) |> MusicDB.Repo.preload(:tracks)
You can type this:
album = Repo.get(Album, 1) |> Repo.preload(:tracks)
Those saved keystrokes start to add up after a while.
Next, you should import the Ecto.Query module. IEx is a great place to try out queries you’re working ...
Read now
Unlock full access