Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename Model.conditions and relation.conditions to .where

  • Loading branch information...
commit 95274b28d95ad85ada25eb0c697ce5650ae488a9 1 parent 1a99337
@lifo lifo authored
View
6 activerecord/lib/active_record/associations.rb
@@ -1717,9 +1717,9 @@ def construct_finder_arel_with_included_associations(options, join_dependency)
select(column_aliases(join_dependency)).
group(construct_group(options[:group], options[:having], scope)).
order(construct_order(options[:order], scope)).
- conditions(construct_conditions(options[:conditions], scope))
+ where(construct_conditions(options[:conditions], scope))
- relation = relation.conditions(construct_arel_limited_ids_condition(options, join_dependency)) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
+ relation = relation.where(construct_arel_limited_ids_condition(options, join_dependency)) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
relation = relation.limit(construct_limit(options[:limit], scope)) if using_limitable_reflections?(join_dependency.reflections)
relation
@@ -1757,7 +1757,7 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)
end
relation = relation.joins(construct_join(options[:joins], scope)).
- conditions(construct_conditions(options[:conditions], scope)).
+ where(construct_conditions(options[:conditions], scope)).
group(construct_group(options[:group], options[:having], scope)).
order(construct_order(options[:order], scope)).
limit(construct_limit(options[:limit], scope)).
View
2  activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -71,7 +71,7 @@ def delete_records(records)
records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
else
relation = arel_table(@reflection.options[:join_table])
- relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id).
+ relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id)))
).delete
end
View
2  activerecord/lib/active_record/associations/has_many_association.rb
@@ -70,7 +70,7 @@ def delete_records(records)
@reflection.klass.delete(records.map { |record| record.id })
else
relation = arel_table(@reflection.table_name)
- relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id).
+ relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
and(Arel::Predicates::In.new(relation[@reflection.klass.primary_key], records.map(&:id)))
).update(relation[@reflection.primary_key_name] => nil)
View
12 activerecord/lib/active_record/base.rb
@@ -651,7 +651,7 @@ def find(*args)
end
end
- delegate :select, :group, :order, :limit, :joins, :conditions, :preload, :eager_load, :to => :arel_table
+ delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :to => :arel_table
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
@@ -885,7 +885,7 @@ def update_all(updates, conditions = nil, options = {})
relation = arel_table
if conditions = construct_conditions(conditions, scope)
- relation = relation.conditions(Arel::SqlLiteral.new(conditions))
+ relation = relation.where(Arel::SqlLiteral.new(conditions))
end
relation = if options.has_key?(:limit) || (scope && scope[:limit])
@@ -948,7 +948,7 @@ def destroy_all(conditions = nil)
# associations or call your <tt>before_*</tt> or +after_destroy+ callbacks, use the +destroy_all+ method instead.
def delete_all(conditions = nil)
if conditions
- arel_table.conditions(Arel::SqlLiteral.new(construct_conditions(conditions, scope(:find)))).delete
+ arel_table.where(Arel::SqlLiteral.new(construct_conditions(conditions, scope(:find)))).delete
else
arel_table.delete
end
@@ -1689,7 +1689,7 @@ def construct_finder_arel(options = {}, scope = scope(:find))
# TODO add lock to Arel
relation = arel_table(options[:from]).
joins(construct_join(options[:joins], scope)).
- conditions(construct_conditions(options[:conditions], scope)).
+ where(construct_conditions(options[:conditions], scope)).
select(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))).
group(construct_group(options[:group], options[:having], scope)).
order(construct_order(options[:order], scope)).
@@ -2564,7 +2564,7 @@ def delete
# be made (since they can't be persisted).
def destroy
unless new_record?
- self.class.arel_table.conditions(self.class.arel_table[self.class.primary_key].eq(id)).delete
+ self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete
end
@destroyed = true
@@ -2851,7 +2851,7 @@ def create_or_update
def update(attribute_names = @attributes.keys)
attributes_with_values = arel_attributes_values(false, false, attribute_names)
return 0 if attributes_with_values.empty?
- self.class.arel_table.conditions(self.class.arel_table[self.class.primary_key].eq(id)).update(attributes_with_values)
+ self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).update(attributes_with_values)
end
# Creates a record with values matching those of the instance attributes
View
2  activerecord/lib/active_record/calculations.rb
@@ -148,7 +148,7 @@ def calculate(operation, column_name, options = {})
else
relation = arel_table(options[:from]).
joins(construct_join(options[:joins], scope)).
- conditions(construct_conditions(options[:conditions], scope)).
+ where(construct_conditions(options[:conditions], scope)).
order(options[:order]).
limit(options[:limit]).
offset(options[:offset])
View
2  activerecord/lib/active_record/relation.rb
@@ -100,7 +100,7 @@ def joins(join, join_type = nil)
end
end
- def conditions(conditions)
+ def where(conditions)
if conditions.blank?
self
else
View
14 activerecord/test/cases/relations_test.rb
@@ -19,8 +19,8 @@ def test_scoped
end
def test_finding_with_conditions
- assert_equal ["David"], Author.conditions(:name => 'David').map(&:name)
- assert_equal ['Mary'], Author.conditions(["name = ?", 'Mary']).map(&:name)
+ assert_equal ["David"], Author.where(:name => 'David').map(&:name)
+ assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)
end
def test_finding_with_order
@@ -54,14 +54,14 @@ def test_finding_with_group
end
def test_finding_with_hash_conditions_on_joined_table
- firms = DependentFirm.joins(:account).conditions({:name => 'RailsCore', :accounts => { :credit_limit => 55..60 }}).to_a
+ firms = DependentFirm.joins(:account).where({:name => 'RailsCore', :accounts => { :credit_limit => 55..60 }}).to_a
assert_equal 1, firms.size
assert_equal companies(:rails_core), firms.first
end
def test_find_all_with_join
developers_on_project_one = Developer.joins('LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id').
- conditions('project_id=1').to_a
+ where('project_id=1').to_a
assert_equal 3, developers_on_project_one.length
developer_names = developers_on_project_one.map { |d| d.name }
@@ -70,7 +70,7 @@ def test_find_all_with_join
end
def test_find_on_hash_conditions
- assert_equal Topic.find(:all, :conditions => {:approved => false}), Topic.conditions({ :approved => false }).to_a
+ assert_equal Topic.find(:all, :conditions => {:approved => false}), Topic.where({ :approved => false }).to_a
end
def test_joins_with_string_array
@@ -97,7 +97,7 @@ def test_find_with_readonly_option
def test_eager_association_loading_of_stis_with_multiple_references
authors = Author.eager_load(:posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } }).
- order('comments.body, very_special_comments_posts.body').conditions('posts.id = 4').to_a
+ order('comments.body, very_special_comments_posts.body').where('posts.id = 4').to_a
assert_equal [authors(:david)], authors
assert_no_queries do
@@ -144,7 +144,7 @@ def test_loading_with_one_association
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
- post = Post.conditions("posts.title = 'Welcome to the weblog'").preload(:comments).first
+ post = Post.where("posts.title = 'Welcome to the weblog'").preload(:comments).first
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
Please sign in to comment.
Something went wrong with that request. Please try again.