Fix user/deepl_account relation

This commit is contained in:
Thelonius Kort
2023-01-09 21:09:46 +01:00
parent 6faf1e02f5
commit 54250a5a95
4 changed files with 6 additions and 5 deletions

View File

@ -7,6 +7,7 @@ defmodule Outlook.Accounts.User do
field :password, :string, virtual: true, redact: true field :password, :string, virtual: true, redact: true
field :hashed_password, :string, redact: true field :hashed_password, :string, redact: true
field :confirmed_at, :naive_datetime field :confirmed_at, :naive_datetime
has_one :deepl_account, Outlook.Translators.DeeplAccount
timestamps() timestamps()
end end

View File

@ -9,8 +9,7 @@ defmodule Outlook.Translators.DeeplAccount do
field :description, :string field :description, :string
field :name, :string field :name, :string
field :our_character_count, :integer field :our_character_count, :integer
field :user_id, :id belongs_to :user, Outlook.Accounts.User
belongs_to :users, User
timestamps() timestamps()
end end
@ -18,7 +17,7 @@ defmodule Outlook.Translators.DeeplAccount do
@doc false @doc false
def changeset(deepl_account, attrs) do def changeset(deepl_account, attrs) do
deepl_account deepl_account
|> cast(attrs, [:name, :description, :auth_key, :character_limit, :character_count, :our_character_count]) |> cast(attrs, [:name, :description, :auth_key, :character_limit, :character_count, :our_character_count, :user_id])
|> validate_required([:name, :description, :auth_key, :character_limit]) |> validate_required([:name, :description, :auth_key, :character_limit, :user_id])
end end
end end

View File

@ -20,6 +20,7 @@ defmodule OutlookWeb.DeeplAccountLive.FormComponent do
phx-change="validate" phx-change="validate"
phx-submit="save" phx-submit="save"
> >
<.input field={{f, :user_id}} type="hidden" />
<.input field={{f, :name}} type="text" label="name" /> <.input field={{f, :name}} type="text" label="name" />
<.input field={{f, :description}} type="text" label="description" /> <.input field={{f, :description}} type="text" label="description" />
<.input field={{f, :auth_key}} type="text" label="auth_key" /> <.input field={{f, :auth_key}} type="text" label="auth_key" />

View File

@ -23,7 +23,7 @@ defmodule OutlookWeb.DeeplAccountLive.Index do
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
socket socket
|> assign(:page_title, "New Deepl account") |> assign(:page_title, "New Deepl account")
|> assign(:deepl_account, %DeeplAccount{}) |> assign(:deepl_account, %DeeplAccount{user_id: socket.assigns.current_user})
end end
defp apply_action(socket, :index, _params) do defp apply_action(socket, :index, _params) do