Last active
June 12, 2017 13:36
Spliting god-object db table into on demand loadable chunks with ecto
This file contains 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 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 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