Skip to content
Browse files

Remove Relation#where_clause

  • Loading branch information...
1 parent dbce07b commit 9acf0af544f2f5dcaf257bdc25047017c972ffce @lifo lifo committed Jan 19, 2010
View
6 activerecord/lib/active_record/relation.rb
@@ -8,7 +8,7 @@ class Relation
include FinderMethods, Calculations, SpawnMethods, QueryMethods
delegate :length, :collect, :map, :each, :all?, :include?, :to => :to_a
- delegate :insert, :update, :where_clause, :to => :arel
+ delegate :insert, :update, :to => :arel
attr_reader :table, :klass
@@ -164,10 +164,6 @@ def with_create_scope
@klass.send(:with_scope, :create => scope_for_create, :find => {}) { yield }
end
- def where_clause(join_string = " AND ")
- arel.send(:where_clauses).join(join_string)
- end
-
def references_eager_loaded_tables?
joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.uniq
(tables_in_string(to_sql) - joined_tables).any?
View
4 activerecord/lib/active_record/relation/finder_methods.rb
@@ -128,7 +128,7 @@ def find_one(id)
record = where(primary_key.eq(id)).first
unless record
- conditions = where_clause(', ')
+ conditions = arel.send(:where_clauses).join(', ')
conditions = " [WHERE #{conditions}]" if conditions.present?
raise RecordNotFound, "Couldn't find #{@klass.name} with ID=#{id}#{conditions}"
end
@@ -154,7 +154,7 @@ def find_some(ids)
if result.size == expected_size
result
else
- conditions = where_clause(', ')
+ conditions = arel.send(:where_clauses).join(', ')
conditions = " [WHERE #{conditions}]" if conditions.present?
error = "Couldn't find all #{@klass.name.pluralize} with IDs "
View
8 activerecord/test/cases/method_scoping_test.rb
@@ -11,7 +11,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_set_conditions
Developer.send(:with_scope, :find => { :conditions => 'just a test...' }) do
- assert_equal '(just a test...)', Developer.scoped.send(:where_clause)
+ assert_equal '(just a test...)', Developer.scoped.arel.send(:where_clauses).join(' AND ')
end
end
@@ -257,7 +257,7 @@ def test_merge_options
Developer.send(:with_scope, :find => { :conditions => 'salary = 80000' }) do
Developer.send(:with_scope, :find => { :limit => 10 }) do
devs = Developer.scoped
- assert_equal '(salary = 80000)', devs.send(:where_clause)
+ assert_equal '(salary = 80000)', devs.arel.send(:where_clauses).join(' AND ')
assert_equal 10, devs.taken
end
end
@@ -285,7 +285,7 @@ def test_append_conditions
Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
Developer.send(:with_scope, :find => { :conditions => 'salary = 80000' }) do
devs = Developer.scoped
- assert_equal "(name = 'David') AND (salary = 80000)", devs.send(:where_clause)
+ assert_equal "(name = 'David') AND (salary = 80000)", devs.arel.send(:where_clauses).join(' AND ')
assert_equal(1, Developer.count)
end
Developer.send(:with_scope, :find => { :conditions => "name = 'Maiha'" }) do
@@ -298,7 +298,7 @@ def test_merge_and_append_options
Developer.send(:with_scope, :find => { :conditions => 'salary = 80000', :limit => 10 }) do
Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
devs = Developer.scoped
- assert_equal "(salary = 80000) AND (name = 'David')", devs.send(:where_clause)
+ assert_equal "(salary = 80000) AND (name = 'David')", devs.arel.send(:where_clauses).join(' AND ')
assert_equal 10, devs.taken
end
end

0 comments on commit 9acf0af

Please sign in to comment.
Something went wrong with that request. Please try again.