Skip to content

Instantly share code, notes, and snippets.

@nietaki
Created October 15, 2019 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nietaki/83bf1c2b5d2d7d9f390646bdd13583ba to your computer and use it in GitHub Desktop.
Save nietaki/83bf1c2b5d2d7d9f390646bdd13583ba to your computer and use it in GitHub Desktop.
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