Permalink
Browse files

add id_field and id_column methods

  • Loading branch information...
1 parent 64338e9 commit 30f5c91ec3dab6cbb1075046305246d718781e11 @ninjudd committed Nov 21, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 lib/record_cache.rb
View
@@ -111,6 +111,14 @@ def delete_all_with_invalidate(conditions = nil)
end
end
+ def id_field
+ connection.quote_column_name(primary_key)
+ end
+
+ def id_column
+ columns_hash[primary_key]
+ end
+
def invalidate_from_conditions(conditions, flag = nil)
if conditions.nil?
# Just invalidate all indexes.
@@ -120,13 +128,12 @@ def invalidate_from_conditions(conditions, flag = nil)
end
# Freeze ids to avoid race conditions.
- sql = "SELECT #{connection.quote_column_name(primary_key)} FROM #{table_name} "
+ sql = "SELECT #{id_field} FROM #{table_name} "
self.send(:add_conditions!, sql, conditions, self.send(:scope, :find))
ids = RecordCache.db(self).select_values(sql)
return if ids.empty?
- primary_col = columns_hash[primary_key]
- conditions = "#{connection.quote_column_name(primary_key)} IN (#{ids.collect {|id| quote_value(id, primary_col)}.join(',')})"
+ conditions = "#{id_field} IN (#{ids.collect {|id| quote_value(id, id_column)}.join(',')})"
if block_given?
# Capture the ids to invalidate in lambdas.

0 comments on commit 30f5c91

Please sign in to comment.