aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-29 17:38:43 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-29 17:38:43 -0700
commit0471fc9f1cf95865a9810b46f1227783fee40ab5 (patch)
tree50c6a1990e7b97b7960a692c9441e686cbcb4902 /activerecord/lib/active_record/relation
parent28c73f012328c8386acfc608f0dfb1a459dbf170 (diff)
parent58becf116580c37c63b89f4a660ebe293f6e7c4e (diff)
downloadrails-0471fc9f1cf95865a9810b46f1227783fee40ab5.tar.gz
rails-0471fc9f1cf95865a9810b46f1227783fee40ab5.tar.bz2
rails-0471fc9f1cf95865a9810b46f1227783fee40ab5.zip
Merge branch 'master' into zomg
* master: (51 commits) order is not guaranteed by this select, so add an order and call first! oracle stores this with microseconds, so convert to seconds before comparing make sure that active connections are not cleared during test when an exception happens clearing active connections in the ConnectionManagement middleware if an exception happens proxy body responses so we close database connections after body is flushed Pass the proper method_name instead of hardcoding to action_name. Quote find_in_batches ORDER BY clause [#6620 state:resolved] Delegate first!, last!, any? and many? to scoped Dont call authenticate_or_request_with_http_basic twice Remove 'warning: ambiguous first argument' when running ActionPack tests Change exists? so that it doesn't instantiate records [#6127 state:resolved] Move mapper_test to the appropriate location Update the wildcard route to be non-greedy by default, therefore be able to match the (.:format) segment [#6605 state:resolved] Fix examples Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call [DHH] make sure we have an active database connection before running each connection management test adding active_connections? to the connection pool for finding open connections adding active_connection? to the connection pool testing app delegation from the ConnectionManagement middleware namespacing connection management tests. :heart: ...
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb2
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb28
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb4
3 files changed, 23 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index bf5a60f458..d52b84179f 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -83,7 +83,7 @@ module ActiveRecord
private
def batch_order
- "#{table_name}.#{primary_key} ASC"
+ "#{quoted_table_name}.#{quoted_primary_key} ASC"
end
end
end
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 25e23a9d55..8fa315bdf3 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -123,9 +123,10 @@ module ActiveRecord
end
end
- # Same as #first! but raises RecordNotFound if no record is returned
- def first!(*args)
- self.first(*args) or raise RecordNotFound
+ # Same as +first+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
+ # is found. Note that <tt>first!</tt> accepts no arguments.
+ def first!
+ first or raise RecordNotFound
end
# A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in all the
@@ -142,9 +143,10 @@ module ActiveRecord
end
end
- # Same as #last! but raises RecordNotFound if no record is returned
- def last!(*args)
- self.last(*args) or raise RecordNotFound
+ # Same as +last+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
+ # is found. Note that <tt>last!</tt> accepts no arguments.
+ def last!
+ last or raise RecordNotFound
end
# A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the
@@ -181,7 +183,9 @@ module ActiveRecord
def exists?(id = nil)
id = id.id if ActiveRecord::Base === id
- relation = select("1").limit(1)
+ join_dependency = construct_join_dependency_for_association_find
+ relation = construct_relation_for_association_find(join_dependency)
+ relation = relation.except(:select).select("1").limit(1)
case id
when Array, Hash
@@ -190,14 +194,13 @@ module ActiveRecord
relation = relation.where(table[primary_key].eq(id)) if id
end
- relation.first ? true : false
+ connection.select_value(relation.to_sql) ? true : false
end
protected
def find_with_associations
- including = (@eager_load_values + @includes_values).uniq
- join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
+ join_dependency = construct_join_dependency_for_association_find
relation = construct_relation_for_association_find(join_dependency)
rows = connection.select_all(relation.to_sql, 'SQL', relation.bind_values)
join_dependency.instantiate(rows)
@@ -205,6 +208,11 @@ module ActiveRecord
[]
end
+ def construct_join_dependency_for_association_find
+ including = (@eager_load_values + @includes_values).uniq
+ ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
+ end
+
def construct_relation_for_association_calculations
including = (@eager_load_values + @includes_values).uniq
join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, including, arel.froms.first)
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 9470e7c6c5..02b7056989 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -62,6 +62,10 @@ module ActiveRecord
relation
end
+ def reorder(*args)
+ except(:order).order(args)
+ end
+
def joins(*args)
return self if args.compact.blank?