Created
October 15, 2019 21:49
-
-
Save nietaki/ef60653ff5294f48ad6e188a2c407340 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.Category do | |
use Ecto.Schema | |
@primary_key {:name, :string, []} | |
embedded_schema do | |
field(:current_popularity, :integer) | |
end | |
end | |
defmodule BlogExample.Schema.Post do | |
use Ecto.Schema | |
schema "posts" do | |
field(:title, :string, null: false) | |
field(:contents, :string, null: false) | |
# this is new | |
belongs_to(:category, BlogExample.Schema.Category, | |
foreign_key: :category_name, | |
references: :name, | |
type: :string | |
) | |
belongs_to(:user, BlogExample.Schema.User) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment