Skip to content

Instantly share code, notes, and snippets.

@LostKobrakai
Last active June 12, 2017 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LostKobrakai/c7b7473235c4d1910445273a443b0d16 to your computer and use it in GitHub Desktop.
Save LostKobrakai/c7b7473235c4d1910445273a443b0d16 to your computer and use it in GitHub Desktop.
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