Browse files

Adding BadgesSashObserver#after_delete support.

  • Loading branch information...
1 parent 1db7341 commit a6c717be8bc7ecd2e2a6e203d4fbbb463fdb4157 @tute tute committed Apr 1, 2012
Showing with 10 additions and 3 deletions.
  1. +9 −2 lib/merit/models/active_record/sash.rb
  2. +1 −1 merit.gemspec
View
11 lib/merit/models/active_record/sash.rb
@@ -9,7 +9,14 @@ def add_badge(badge_id)
BadgesSash.create(sash_id: self.id, badge_id: badge_id)
end
def rm_badge(badge_id)
- ActiveRecord::Base.connection.execute("DELETE FROM badges_sashes
- WHERE badge_id = #{badge_id} AND sash_id = #{self.id}")
+ badges_sashes = BadgesSash.where(:badge_id => badge_id, :sash_id => self.id)
+ # ActiveRecord::Relation#delete 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')
+ BadgesSashObserver.instance.after_delete(badges_sash)
+ end
end
end
View
2 merit.gemspec
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.summary = "General reputation Rails engine."
s.description = "General reputation Rails engine."
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
- s.version = "0.3.2"
+ s.version = "0.3.3"
s.authors = ["Tute Costa"]
s.email = 'tutecosta@gmail.com'
s.add_dependency 'ambry'

0 comments on commit a6c717b

Please sign in to comment.