Permalink
Browse files

Refactored primary_key to look up for the real primary_key and cache it.

  • Loading branch information...
1 parent 18b2a3c commit debd111a39a683592873e7af2d277233b6ec14d2 @miloops miloops committed Feb 19, 2010
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/arel/engines/sql/relations/relation.rb
@@ -1,5 +1,6 @@
module Arel
class Relation
+ @@tables_primary_keys = {}
def compiler
@compiler ||= begin
@@ -22,10 +23,10 @@ def inclusion_predicate_sql
end
def primary_key
- @primary_key ||= begin
- table.name.classify.constantize.primary_key
- rescue NameError
- nil
+ if @@tables_primary_keys.has_key?(table.name)
+ @@tables_primary_keys[table.name]
+ else
+ @@tables_primary_keys[table.name] = engine.primary_key(table.name)
end
end

0 comments on commit debd111

Please sign in to comment.