Write an Ecto Schema

Databases revolve around data, so we need a way to define the types, tables, and relationships of our application’s data layer. Ecto solves this with schemas. We use schemas to define our data structure, and then Ecto uses the schema definition to operate on our application’s data.

We’ll write a schema to hold SMS messages, and then we’ll look at how Ecto fields and associations work. Let’s jump in!

Phoenix Generators

images/aside-icons/info.png

Phoenix provides a generator that’s used to define a schema file and migration file all at once. The reason why we don’t use that in this book is simple: I don’t like using most generators. I prefer the control ...

Get From Ruby to Elixir 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.