mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add notification_id column to user_badges.
This commit is contained in:
@@ -35,6 +35,7 @@ end
|
||||
# updated_at :datetime
|
||||
# allow_title :boolean default(FALSE), not null
|
||||
# multiple_grant :boolean default(FALSE), not null
|
||||
# icon :string(255) default("fa-certificate")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
||||
@@ -2,28 +2,25 @@ class UserBadge < ActiveRecord::Base
|
||||
belongs_to :badge
|
||||
belongs_to :user
|
||||
belongs_to :granted_by, class_name: 'User'
|
||||
belongs_to :notification, dependent: :destroy
|
||||
|
||||
validates :badge_id, presence: true, uniqueness: {scope: :user_id}, if: 'badge.single_grant?'
|
||||
validates :user_id, presence: true
|
||||
validates :granted_at, presence: true
|
||||
validates :granted_by, presence: true
|
||||
|
||||
# This may be inefficient, but not very easy to optimize unless the data hash
|
||||
# is converted into a hstore.
|
||||
def notification
|
||||
@notification ||= self.user.notifications.where(notification_type: Notification.types[:granted_badge]).where("data LIKE ?", "%" + self.badge_id.to_s + "%").select {|n| n.data_hash["badge_id"] == self.badge_id }.first
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: user_badges
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# badge_id :integer not null
|
||||
# user_id :integer not null
|
||||
# granted_at :datetime not null
|
||||
# granted_by_id :integer not null
|
||||
# id :integer not null, primary key
|
||||
# badge_id :integer not null
|
||||
# user_id :integer not null
|
||||
# granted_at :datetime not null
|
||||
# granted_by_id :integer not null
|
||||
# post_id :integer
|
||||
# notification_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user