Created
September 12, 2022 14:27
-
-
Save wttj-tech/270a85d38d2794a13987b5c7a786d303 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 User do | |
use Ecto.Schema | |
use EctoAnon.Schema | |
anon_schema [ | |
:lastname, | |
:email, | |
:followers, | |
:favorite_quote, | |
:quotes, | |
:last_sign_in_at | |
] | |
schema "users" do | |
field(:firstname, :string) | |
field(:lastname, :string) | |
field(:email, :string) | |
field(:last_sign_in_at, :utc_datetime) | |
has_many(:comments, Comment, foreign_key: :author_id, references: :id) | |
embeds_one(:favorite_quote, Quote) | |
embeds_many(:quotes, Quote) | |
many_to_many( | |
:followers, | |
__MODULE__, | |
join_through: Follower, | |
join_keys: [follower_id: :id, followee_id: :id] | |
) | |
end | |
end | |
defmodule Quote do | |
use Ecto.Schema | |
use EctoAnon.Schema | |
anon_schema([ | |
:quote, | |
:author | |
]) | |
embedded_schema do | |
field(:quote, :string) | |
field(:author, :string) | |
end | |
end | |
defmodule Follower do | |
use Ecto.Schema | |
schema "followers" do | |
field(:follower_id, :id) | |
field(:followee_id, :id) | |
timestamps() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment