Sha256: 7c84a578f8e0a94e529b28bf1fda601ccc2e042a377426d4d810a5375068f9a7

Contents?: true

Size: 782 Bytes

Versions: 10

Compression:

Stored size: 782 Bytes

Contents

class Sash < ActiveRecord::Base
  has_many :badges_sashes

  def badge_ids
    badges_sashes.collect(&:badge_id)
  end

  def add_badge(badge_id)
    bs = BadgesSash.new
    bs.sash_id = self.id
    bs.badge_id = badge_id
    bs.save
  end
  def rm_badge(badge_id)
    badges_sashes = BadgesSash.where(:badge_id => badge_id, :sash_id => self.id)
    # ActiveRecord::Relation#delete|destroy(_all) doesn't work with composite keys.
    # Badge is not AR model (Ambry) so can't do self.badges.find(badge_id).delete
    badges_sash = badges_sashes.first
    badges_sashes.delete_all
    # delete doesn't run callbacks, do it by hand
    if Object.const_defined?('BadgesSashObserver') && badges_sash.present?
      BadgesSashObserver.instance.after_delete(badges_sash)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
merit-0.9.5 lib/merit/models/active_record/sash.rb
merit-0.9.4 lib/merit/models/active_record/sash.rb
merit-0.9.3 lib/merit/models/active_record/sash.rb
merit-0.9.2 lib/merit/models/active_record/sash.rb
merit-0.9.1 lib/merit/models/active_record/sash.rb
merit-0.9.0 lib/merit/models/active_record/sash.rb
merit-0.8.1 lib/merit/models/active_record/sash.rb
merit-0.8.0 lib/merit/models/active_record/sash.rb
merit-0.7.1 lib/merit/models/active_record/sash.rb
merit-0.7.0 lib/merit/models/active_record/sash.rb