update relations

This commit is contained in:
Daniel Yrovas 2025-01-10 21:52:22 +11:00
parent 90414e6b93
commit 4ad3973e9b
Signed by: danielyrovas
SSH key fingerprint: SHA256:1avlGZQpGW038lBkNI5lOS7f0hIPM7ecJen2/P1MCCU
6 changed files with 14 additions and 7 deletions

View file

@ -9,6 +9,8 @@ defmodule Wild.Accounts.User do
field :current_password, :string, virtual: true, redact: true field :current_password, :string, virtual: true, redact: true
field :confirmed_at, :utc_datetime field :confirmed_at, :utc_datetime
has_many :book_reads, Wild.BookReads.BookRead
timestamps(type: :utc_datetime) timestamps(type: :utc_datetime)
end end

View file

@ -9,8 +9,9 @@ defmodule Wild.BookReads.BookRead do
field :thoughts, :string field :thoughts, :string
field :read_start, :utc_datetime field :read_start, :utc_datetime
field :read_finish, :utc_datetime field :read_finish, :utc_datetime
field :user_id, :id, primary_key: true
field :book_id, :id, primary_key: true belongs_to :user, Wild.Accounts.User, type: :id, primary_key: true
belongs_to :book, Wild.Books.Book, type: :id, primary_key: true
timestamps(type: :utc_datetime) timestamps(type: :utc_datetime)
end end

View file

@ -9,6 +9,8 @@ defmodule Wild.Books.Author do
field :year_born, :string field :year_born, :string
field :year_died, :string field :year_died, :string
has_many :books, Wild.Books.Book
timestamps(type: :utc_datetime) timestamps(type: :utc_datetime)
end end

View file

@ -6,7 +6,9 @@ defmodule Wild.Books.Book do
field :title, :string field :title, :string
field :blurb, :string field :blurb, :string
field :publication_year, :string field :publication_year, :string
field :author_id, :id
belongs_to :author, Wild.Books.Author
# field :author_id, :id
timestamps(type: :utc_datetime) timestamps(type: :utc_datetime)
end end

View file

@ -4,7 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="csrf-token" content={get_csrf_token()} /> <meta name="csrf-token" content={get_csrf_token()} />
<.live_title default="Wild" suffix=" · Phoenix Framework"> <.live_title default="Call of the Wild" suffix="">
{assigns[:page_title]} {assigns[:page_title]}
</.live_title> </.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} /> <link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />

View file

@ -2,14 +2,14 @@ defmodule Wild.Repo.Migrations.CreateBookReads do
use Ecto.Migration use Ecto.Migration
def change do def change do
create table(:book_reads) do create table(:book_reads, primary_key: false) do
add :rating, :integer add :rating, :integer
add :thoughts, :string add :thoughts, :string
add :read_start, :utc_datetime add :read_start, :utc_datetime
add :read_finish, :utc_datetime add :read_finish, :utc_datetime
add :progress, :integer add :progress, :integer
add :user_id, references(:users, on_delete: :nothing) add :user_id, references(:users, on_delete: :delete_all), primary_key: true
add :book_id, references(:books, on_delete: :nothing) add :book_id, references(:books, on_delete: :delete_all), primary_key: true
timestamps(type: :utc_datetime) timestamps(type: :utc_datetime)
end end