diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-02-25 11:40:30 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-02-25 18:00:34 +0100 |
commit | e0356990856abc9a84e6e038e7b06e2931502728 (patch) | |
tree | c4c645f0b335f89bd0e47c92e48a45db846813df /activerecord/lib | |
parent | 45321a69b3c01ce8a4cfef6cdf13381d73e10cd3 (diff) | |
download | rails-e0356990856abc9a84e6e038e7b06e2931502728.tar.gz rails-e0356990856abc9a84e6e038e7b06e2931502728.tar.bz2 rails-e0356990856abc9a84e6e038e7b06e2931502728.zip |
Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
Fixes #9275.
When `#order` is called with a Symbol this patch will prepend the quoted_table_name.
Before the postgresql adapter failed to build queries containg a join and an order
with a symbol.
This expansion happens for all adapters.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 225677085f..4b8c40592e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -285,6 +285,11 @@ module ActiveRecord references.map! { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }.compact! references!(references) if references.any? + # if a symbol is given we prepend the quoted table name + args = args.map { |arg| + arg.is_a?(Symbol) ? "#{quoted_table_name}.#{arg} ASC" : arg + } + self.order_values = args + self.order_values self end |