diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-02-19 12:08:47 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-02-19 12:08:47 -0300 |
commit | debd111a39a683592873e7af2d277233b6ec14d2 (patch) | |
tree | d06d4d023ec2d81944f51204eba2e027566a2f8e /lib | |
parent | 18b2a3ce6b4519b7d5e0f4a63bc6cfb5b8808632 (diff) | |
download | rails-debd111a39a683592873e7af2d277233b6ec14d2.tar.gz rails-debd111a39a683592873e7af2d277233b6ec14d2.tar.bz2 rails-debd111a39a683592873e7af2d277233b6ec14d2.zip |
Refactored primary_key to look up for the real primary_key and cache it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/engines/sql/relations/relation.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb index 52b91c71ea..4249cf9b0d 100644 --- a/lib/arel/engines/sql/relations/relation.rb +++ b/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 @@ module Arel 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 |