1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rename Model.conditions and relation.conditions to .where

This commit is contained in:
Pratik Naik 2009-12-26 03:50:57 +05:30
parent 1a99337180
commit 95274b28d9
7 changed files with 20 additions and 20 deletions

View file

@ -1717,9 +1717,9 @@ module ActiveRecord
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 @@ module ActiveRecord
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 file

@ -71,7 +71,7 @@ module ActiveRecord
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 file

@ -70,7 +70,7 @@ module ActiveRecord
@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 file

@ -651,7 +651,7 @@ module ActiveRecord #:nodoc:
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 @@ module ActiveRecord #:nodoc:
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 @@ module ActiveRecord #:nodoc:
# 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 @@ module ActiveRecord #:nodoc:
# 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 @@ module ActiveRecord #:nodoc:
# 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 @@ module ActiveRecord #:nodoc:
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 file

@ -148,7 +148,7 @@ module ActiveRecord
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 file

@ -100,7 +100,7 @@ module ActiveRecord
end
end
def conditions(conditions)
def where(conditions)
if conditions.blank?
self
else

View file

@ -19,8 +19,8 @@ class RelationTest < ActiveRecord::TestCase
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 @@ class RelationTest < ActiveRecord::TestCase
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 @@ class RelationTest < ActiveRecord::TestCase
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 @@ class RelationTest < ActiveRecord::TestCase
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 @@ class RelationTest < ActiveRecord::TestCase
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))