Skip to content

Instantly share code, notes, and snippets.

@LostKobrakai
Last active June 12, 2017 13:36
Spliting god-object db table into on demand loadable chunks with ecto
# Basic user with just name, email, password
user = Repo.get User, 1
# Load profile
user = Repo.preload(user, :profile)
profile = user.profile
defmodule User do
use Ecto.Schema
schema "users" do
field :name
field :email
field :password
has_one :profile, Profile, foreign_key: :id
timestamps()
end
end
defmodule Profile do
use Ecto.Schema
schema "users" do
field :first_name
field :last_name
field :avatar
field :company
field :role
field :telephone
belongs_to :user, User, foreign_key: :id
timestamps()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment