diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-23 19:45:14 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-23 19:45:14 -0300 |
commit | 97811698ab0e68b33fbf3067c3764e385dd75d53 (patch) | |
tree | 4decda7f5a8cdb87119ced88fb49c12680736700 | |
parent | a9486193c8c6250d56bfb0258be50025f7f62f5e (diff) | |
download | rails-97811698ab0e68b33fbf3067c3764e385dd75d53.tar.gz rails-97811698ab0e68b33fbf3067c3764e385dd75d53.tar.bz2 rails-97811698ab0e68b33fbf3067c3764e385dd75d53.zip |
If the class or method isn't defined use "id" as primary_key.
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 471fceabd8..b90d380c64 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -48,7 +48,12 @@ module Arel conditions << " LIMIT #{taken}" if engine.adapter_name != "MySQL" - quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) + 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 + conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" end end |