Created
October 15, 2019 21:26
-
-
Save nietaki/83bf1c2b5d2d7d9f390646bdd13583ba to your computer and use it in GitHub Desktop.
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 BlogExample.Schema.User do | |
use Ecto.Schema | |
schema "users" do | |
field(:username, :string, null: false) | |
field(:full_name, :string) | |
has_many(:posts, BlogExample.Schema.Post) | |
has_many(:comments, BlogExample.Schema.Comment) | |
end | |
end | |
defmodule BlogExample.Schema.Post do | |
use Ecto.Schema | |
schema "posts" do | |
field(:title, :string, null: false) | |
field(:contents, :string, null: false) | |
belongs_to(:user, BlogExample.Schema.User) | |
end | |
end | |
defmodule BlogExample.Schema.Comment do | |
use Ecto.Schema | |
schema "comments" do | |
field(:contents, :string, null: false) | |
belongs_to(:user, BlogExample.Schema.User) | |
belongs_to(:post, BlogExample.Schema.Post) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment