Chapter 8. Making changes with Ecto.Changeset

 

This chapter covers

  • Discovering how Ecto deals with database updates
  • Creating a changeset for Auction.Item
  • Using changesets to update the database

So far, you’ve configured your Auction app to do a few nice things:

  • Get Auction.Items from the database
  • Save new Auction.Items to the database via IEx
  • Display the Auction.Items in the database in a web page

It definitely needs to do a few more things before the investors come knocking on your door, begging to give you their money. In this chapter, we’ll focus on updating data in the database. It sounds like it should be a simple thing to do, since you already know how to get and store records, but it’s a bit more complex than that. Most times, added complexity is a bad thing. But with Ecto’s changesets, I’d argue that the complexity is welcome and beneficial. By the end of this chapter, I think you’ll agree.

8.1. Can’t I just ... update?

Nope. You can’t.

Let me explain: Say you wanted to update your WarGames Bluray auction item. Using the code as it was at the end of chapter 7, you could attempt to use Ecto.Repo.update/2.

8.2. Now you can update!

 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest