Search⌘ K
AI Features

Choose Between Embedded Schemas and Associations

Explore when to use embedded schemas or associations within Ecto by understanding their benefits and limitations, including performance impacts, data structure flexibility, and database integrity.

Advantages of embedded schemas

Embedded schemas have some advantages over associations.

  • Since the child records are stored with the parent, we don’t have to use joins or Repo.preload to fetch them. This can help with performance because we can avoid extra round-trips to the database. It also means the data is stored together on disk and in memory, which reduces expensive disk seek ...