Chapter 11. Associating records and accepting bids

This chapter covers

  • Allowing users to bid on items
  • Defining Ecto associations between items, bids, and users
  • Using Ecto to load associated schemas
  • Preloading associations to avoid N+1 queries

In the past few chapters, we’ve discussed using Ecto to define schemas for users and items. You can create new auction items, register a user, and log in and out as a user. There are a couple of things missing, though:

  • There’s no way for a user to bid on an item.
  • Items aren’t owned by anyone. In fact, a random stranger could create new auction items on your site right now.

Both of these points are similar in that they rely on associating one record or schema with another. Bids (which don’t yet exist) ...

Get Phoenix in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.