feat: 上位タグのバグ修正(#174) (#175)
#174 エラー回避と誤記修正 #174 完了 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #175
This commit was merged in pull request #175.
This commit is contained in:
@@ -2,7 +2,7 @@ class TagImplication < ApplicationRecord
|
||||
belongs_to :tag, class_name: 'Tag'
|
||||
belongs_to :parent_tag, class_name: 'Tag'
|
||||
|
||||
validates :tag_id, presence: true
|
||||
validates :tag_id, presence: true, uniqueness: { scope: :parent_tag_id }
|
||||
validates :parent_tag_id, presence: true
|
||||
|
||||
validate :parent_tag_mustnt_be_itself
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class AddUniqueIndexToTagImplications < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
ti1
|
||||
FROM
|
||||
tag_implications ti1
|
||||
INNER JOIN
|
||||
tag_implications ti2
|
||||
ON
|
||||
ti1.tag_id = ti2.tag_id
|
||||
AND ti1.parent_tag_id = ti2.parent_tag_id
|
||||
AND ti1.id > ti2.id
|
||||
;
|
||||
SQL
|
||||
|
||||
add_index :tag_implications, [:tag_id, :parent_tag_id],
|
||||
unique: true,
|
||||
name: 'index_tag_implications_on_tag_id_and_parent_tag_id'
|
||||
end
|
||||
|
||||
def down
|
||||
# NOTE: 重複削除は復元されなぃ.
|
||||
remove_index :tag_implications,
|
||||
name: 'index_tag_implications_on_tag_id_and_parent_tag_id'
|
||||
end
|
||||
end
|
||||
Generated
+2
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_10_09_222200) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_12_10_123200) do
|
||||
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
@@ -120,6 +120,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_10_09_222200) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["parent_tag_id"], name: "index_tag_implications_on_parent_tag_id"
|
||||
t.index ["tag_id", "parent_tag_id"], name: "index_tag_implications_on_tag_id_and_parent_tag_id", unique: true
|
||||
t.index ["tag_id"], name: "index_tag_implications_on_tag_id"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user