From d375caf7a3a2601ff00b127537e8d78d387d0ad5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 30 Nov 2013 10:20:22 +0000 Subject: [PATCH 1/1] Update to CPK 6.0.1 and drop monkey patch --- Gemfile | 2 +- Gemfile.lock | 21 ++++---- config/initializers/composite_primary_keys.rb | 48 ------------------- 3 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 config/initializers/composite_primary_keys.rb diff --git a/Gemfile b/Gemfile index 11008d943..94eb39681 100644 --- a/Gemfile +++ b/Gemfile @@ -41,7 +41,7 @@ gem 'rinku', '>= 1.2.2', :require => 'rails_rinku' gem 'oauth-plugin', '>= 0.5.1' gem 'open_id_authentication', '>= 1.1.0' gem 'validates_email_format_of', '>= 1.5.1' -gem 'composite_primary_keys', '>= 6.0.0' +gem 'composite_primary_keys', '>= 6.0.1' gem 'http_accept_language', '~> 2.0.0' gem 'paperclip', '~> 3.0' gem 'deadlock_retry', '>= 1.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index d8dae468a..2065dabdd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GEM erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionpack-page_caching (1.0.1) + actionpack-page_caching (1.0.2) actionpack (>= 4.0.0, < 5) activemodel (4.0.1) activesupport (= 4.0.1) @@ -43,7 +43,7 @@ GEM coffee-script-source execjs coffee-script-source (1.6.3) - composite_primary_keys (6.0.0) + composite_primary_keys (6.0.1) activerecord (>= 4.0.0) dalli (2.6.4) deadlock_retry (1.2.0) @@ -75,7 +75,7 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.25) + mime-types (1.25.1) mini_portile (0.5.2) minitest (4.7.5) multi_json (1.8.2) @@ -107,12 +107,11 @@ GEM mime-types pg (0.17.0) polyglot (0.3.3) - psych (2.0.1) + psych (2.0.2) r2 (0.2.2) rack (1.5.2) - rack-cors (0.2.8) - rack - rack-openid (1.4.0) + rack-cors (0.2.9) + rack-openid (1.4.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) rack-test (0.6.2) @@ -144,7 +143,7 @@ GEM railties (>= 4.0.0, < 5.0) sass (>= 3.1.10) sprockets-rails (~> 2.0.0) - sprockets (2.10.0) + sprockets (2.10.1) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -157,12 +156,12 @@ GEM thread_safe (0.1.3) atomic tilt (1.4.1) - timecop (0.6.3) + timecop (0.7.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) tzinfo (0.3.38) - uglifier (2.3.0) + uglifier (2.3.1) execjs (>= 0.3.0) json (>= 1.8.0) validates_email_format_of (1.5.3) @@ -176,7 +175,7 @@ DEPENDENCIES actionpack-page_caching bigdecimal (~> 1.1.0) coffee-rails (~> 4.0.0) - composite_primary_keys (>= 6.0.0) + composite_primary_keys (>= 6.0.1) dalli deadlock_retry (>= 1.2.0) dynamic_form diff --git a/config/initializers/composite_primary_keys.rb b/config/initializers/composite_primary_keys.rb deleted file mode 100644 index ed4d5f2c9..000000000 --- a/config/initializers/composite_primary_keys.rb +++ /dev/null @@ -1,48 +0,0 @@ -# Monkey patch composite_primary_keys pending the resolution of: -# https://github.com/composite-primary-keys/composite_primary_keys/pull/170 -module ActiveRecord - module Associations - class HasManyAssociation - def delete_records(records, method) - if method == :destroy - records.each { |r| r.destroy } - update_counter(-records.length) unless inverse_updates_counter_cache? - else - if records == :all - scope = self.scope - else - # CPK - # keys = records.map { |r| r[reflection.association_primary_key] } - # scope = scope.where(reflection.association_primary_key => keys) - table = Arel::Table.new(reflection.table_name) - and_conditions = records.map do |record| - eq_conditions = Array(reflection.association_primary_key).map do |name| - table[name].eq(record[name]) - end - Arel::Nodes::And.new(eq_conditions) - end - - condition = and_conditions.shift - and_conditions.each do |and_condition| - condition = condition.or(and_condition) - end - - scope = self.scope.where(condition) - end - - if method == :delete_all - update_counter(-scope.delete_all) - else - # CPK - # update_counter(-scope.update_all(reflection.foreign_key => nil)) - updates = Array(reflection.foreign_key).inject(Hash.new) do |hash, name| - hash[name] = nil - hash - end - update_counter(-scope.update_all(updates)) - end - end - end - end - end -end -- 2.43.2