mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-25 01:10:59 +00:00
add unique constraint on songs changeset
This commit is contained in:
parent
023ddc2806
commit
11d5cd8cdd
2 changed files with 5 additions and 1 deletions
|
@ -196,7 +196,7 @@ defmodule LiveBeats.MediaLibrary do
|
|||
{:error, failed_op, failed_val, _changes} ->
|
||||
failed_op =
|
||||
case failed_op do
|
||||
{:song, _number} -> :invalid_song
|
||||
{:song, _number} -> "Invalid song (#{failed_val.changes.title})"
|
||||
:is_songs_count_updated? -> :invalid
|
||||
failed_op -> failed_op
|
||||
end
|
||||
|
|
|
@ -34,6 +34,10 @@ defmodule LiveBeats.MediaLibrary.Song do
|
|||
song
|
||||
|> cast(attrs, [:album_artist, :artist, :title, :attribution, :date_recorded, :date_released])
|
||||
|> validate_required([:artist, :title])
|
||||
|> unique_constraint(:title,
|
||||
message: "is a duplicated from another song",
|
||||
name: "songs_user_id_title_artist_index"
|
||||
)
|
||||
end
|
||||
|
||||
def put_user(%Ecto.Changeset{} = changeset, %Accounts.User{} = user) do
|
||||
|
|
Loading…
Reference in a new issue