fix: Update associations when a label is updated (#3046)

This commit is contained in:
Pranav Raj S
2021-09-21 10:16:32 +05:30
committed by GitHub
parent aaadd61e09
commit b59e73b10b
7 changed files with 124 additions and 5 deletions

View File

@@ -25,6 +25,8 @@ class Label < ApplicationRecord
format: { with: UNICODE_CHARACTER_NUMBER_HYPHEN_UNDERSCORE },
uniqueness: { scope: :account_id }
after_update_commit :update_associated_models
before_validation do
self.title = title.downcase if attribute_present?('title')
end
@@ -40,4 +42,12 @@ class Label < ApplicationRecord
def events
account.events.where(conversation_id: conversations.pluck(:id))
end
private
def update_associated_models
return unless title_previously_changed?
Labels::UpdateJob.perform_later(title, title_previously_was, account_id)
end
end