Last active
June 12, 2017 13:36
-
-
Save LostKobrakai/c7b7473235c4d1910445273a443b0d16 to your computer and use it in GitHub Desktop.
Spliting god-object db table into on demand loadable chunks with ecto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic user with just name, email, password | |
user = Repo.get User, 1 | |
# Load profile | |
user = Repo.preload(user, :profile) | |
profile = user.profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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