# Error moving sub category to top level with duplicate name

**URL:** <https://meta.discourse.org/t/error-moving-sub-category-to-top-level-with-duplicate-name/31614>\
**Category:** Bug\
**Created:** [7월 31, 2015, 4:21오후 UTC](https://meta.discourse.org/t/error-moving-sub-category-to-top-level-with-duplicate-name/31614 "2015-07-31T16:21:36Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [8월 1, 2015, 12:10오전 UTC](https://meta.discourse.org/t/error-moving-sub-category-to-top-level-with-duplicate-name/31614/4 "2015-08-01T00:10:49Z")

</div>

Here’s the validation logic around parent categories:

```plaintext
  def parent_category_validator
    if parent_category_id
      errors.add(:base, I18n.t("category.errors.self_parent")) if parent_category_id == id
      errors.add(:base, I18n.t("category.errors.uncategorized_parent")) if uncategorized?

      grandfather_id = Category.where(id: parent_category_id).pluck(:parent_category_id).first
      errors.add(:base, I18n.t("category.errors.depth")) if grandfather_id
    end
  end

```

That shouldn’t trigger when making the parent nil.

We also have this:

```plaintext
  validates :name, if: Proc.new { |c| c.new_record? || c.name_changed? },
                   presence: true,
                   uniqueness: { scope: :parent_category_id, case_sensitive: false },
                   length: { in: 1..50 }

```

Is there, perhaps, [another top-level category](https://what.thedailywtf.com/c/general-help/coder-challenge) with [the same name?](https://what.thedailywtf.com/c/coder-challenge)

---

_[View the full topic](https://meta.discourse.org/t/error-moving-sub-category-to-top-level-with-duplicate-name/31614)._
