Using Changesets Without Schemas
Up to this point, our changesets have been based on the schemas defined in our music_db app: Artist, Genre, and so forth. But changesets don’t actually need Ecto schemas—they can be created with plain maps that define field names and types. This means that you can leverage the casting, filtering, and validation features of changesets, even if the data is not being persisted in a database.
Let’s say that our application will have an “Advanced Search” feature. We’ll allow users to specify a number of different fields to help them find what they’re looking for: artist names, album titles, dates, and the like. We can validate the form using the features of Ecto.Changeset, and then report any errors back to the user. ...
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.
Read now
Unlock full access