From 413c19a97dd04939d53abd58c6cd3f300ff3b74e Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 4 Dec 2019 16:42:13 -0500 Subject: [PATCH] handle aliases in tag input --- lib/philomena/tags.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/philomena/tags.ex b/lib/philomena/tags.ex index f724b2cc..4fc61da8 100644 --- a/lib/philomena/tags.ex +++ b/lib/philomena/tags.ex @@ -17,8 +17,7 @@ defmodule Philomena.Tags do |> where([t], t.name in ^tag_names) |> preload([:implied_tags, aliased_tag: :implied_tags]) |> Repo.all() - |> Enum.map(& &1.aliased_tag || &1) - |> Enum.uniq() + |> Enum.uniq_by(& &1.name) existent_tag_names = existent_tags @@ -28,6 +27,11 @@ defmodule Philomena.Tags do tag_names |> Enum.reject(&existent_tag_names[&1]) + # Now get rid of the aliases + existent_tags = + existent_tags + |> Enum.map(& &1.aliased_tag || &1) + new_tags = nonexistent_tag_names |> Enum.map(fn name ->