diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-02-18 18:11:43 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-02-18 18:11:43 -0300 |
commit | 1c0d7dc7f62e8744b476464f8aefc1867986f0bd (patch) | |
tree | 0dc8364c74fd721abbd5d0d3dd3f83b5a211c45a | |
parent | f37c4a4d690888aa5cf8e54c8b404dd10f219f46 (diff) | |
download | rails-1c0d7dc7f62e8744b476464f8aefc1867986f0bd.tar.gz rails-1c0d7dc7f62e8744b476464f8aefc1867986f0bd.tar.bz2 rails-1c0d7dc7f62e8744b476464f8aefc1867986f0bd.zip |
Moved primary_key to relation, send pk to engine, to build a better
query if possible.
-rw-r--r-- | lib/arel/engines/sql/engine.rb | 2 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/compiler.rb | 9 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/relation.rb | 8 |
3 files changed, 11 insertions, 8 deletions
diff --git a/lib/arel/engines/sql/engine.rb b/lib/arel/engines/sql/engine.rb index 5bb8463699..82915fe890 100644 --- a/lib/arel/engines/sql/engine.rb +++ b/lib/arel/engines/sql/engine.rb @@ -20,7 +20,7 @@ module Arel module CRUD def create(relation) - connection.insert(relation.to_sql) + connection.insert(relation.to_sql, nil, relation.primary_key) end def read(relation) diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb index 46f728a7bd..4bc169096a 100644 --- a/lib/arel/engines/sql/relations/compiler.rb +++ b/lib/arel/engines/sql/relations/compiler.rb @@ -22,13 +22,8 @@ module Arel end def limited_update_conditions(conditions) - begin - quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) - rescue NameError - quote_primary_key = engine.quote_column_name("id") - end - - "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" + quoted_primary_key = engine.quote_table_name(primary_key) + "WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" end protected diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb index 13e9f0a6a2..5038e1db81 100644 --- a/lib/arel/engines/sql/relations/relation.rb +++ b/lib/arel/engines/sql/relations/relation.rb @@ -20,5 +20,13 @@ module Arel def inclusion_predicate_sql "IN" end + + def primary_key + @primary_key ||= begin + table.name.classify.constantize.primary_key + rescue NameError + "id" + end + end end end |