From a0c06606fb06e4cea659b02f53bc8e3e823fbe71 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 24 Jan 2025 14:29:38 +0000 Subject: [PATCH] Validate before constructing a complete record --- lib/music_library/records/record.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex index 6591c8ff..57a0b143 100644 --- a/lib/music_library/records/record.ex +++ b/lib/music_library/records/record.ex @@ -29,7 +29,6 @@ defmodule MusicLibrary.Records.Record do timestamps(type: :utc_datetime) end - @doc false def changeset(record, attrs) do record |> cast(attrs, [ @@ -46,12 +45,12 @@ defmodule MusicLibrary.Records.Record do :cover_data, :purchased_at ]) - |> cast_embed(:artists, with: &artist_changeset/2) + |> cast_embed(:artists) + |> validate_required([:type, :title, :musicbrainz_id, :release, :genres]) + |> unique_constraint(:musicbrainz_id, name: "records_musicbrainz_id_format_index") |> generate_cover_hash() |> update_release_ids() |> update_included_release_group_ids() - |> validate_required([:type, :title, :musicbrainz_id, :release, :genres]) - |> unique_constraint(:musicbrainz_id, name: "records_musicbrainz_id_format_index") end def child_release_groups(record) do