From a3683fd0e4980ae4926497ba7c7b7e8606f3e88e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 8 Jul 2011 01:12:09 +0900 Subject: find(:all) => all --- activerecord/lib/active_record/associations.rb | 36 +++++++++++++------------- activerecord/lib/active_record/errors.rb | 2 +- activerecord/lib/active_record/fixtures.rb | 6 ++--- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 2cbfa42718..b23b51e832 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -191,7 +191,7 @@ module ActiveRecord # * Project#portfolio, Project#portfolio=(portfolio), Project#portfolio.nil? # * Project#project_manager, Project#project_manager=(project_manager), Project#project_manager.nil?, # * Project#milestones.empty?, Project#milestones.size, Project#milestones, Project#milestones<<(milestone), - # Project#milestones.delete(milestone), Project#milestones.find(milestone_id), Project#milestones.find(:all, options), + # Project#milestones.delete(milestone), Project#milestones.find(milestone_id), Project#milestones.all(options), # Project#milestones.build, Project#milestones.create # * Project#categories.empty?, Project#categories.size, Project#categories, Project#categories<<(category1), # Project#categories.delete(category1) @@ -669,7 +669,7 @@ module ActiveRecord # To iterate over these one hundred posts, we'll generate 201 database queries. Let's # first just optimize it for retrieving the author: # - # Post.find(:all, :include => :author).each do |post| + # Post.all(:include => :author).each do |post| # # This references the name of the +belongs_to+ association that also used the :author # symbol. After loading the posts, find will collect the +author_id+ from each one and load @@ -678,7 +678,7 @@ module ActiveRecord # # We can improve upon the situation further by referencing both associations in the finder with: # - # Post.find(:all, :include => [ :author, :comments ]).each do |post| + # Post.all(:include => [ :author, :comments ]).each do |post| # # This will load all comments with a single query. This reduces the total number of queries # to 3. More generally the number of queries will be 1 plus the number of associations @@ -686,7 +686,7 @@ module ActiveRecord # # To include a deep hierarchy of associations, use a hash: # - # Post.find(:all, :include => [ :author, { :comments => { :author => :gravatar } } ]).each do |post| + # Post.all(:include => [ :author, { :comments => { :author => :gravatar } } ]).each do |post| # # That'll grab not only all the comments but all their authors and gravatar pictures. # You can mix and match symbols, arrays and hashes in any combination to describe the @@ -720,7 +720,7 @@ module ActiveRecord # has_many :approved_comments, :class_name => 'Comment', :conditions => ['approved = ?', true] # end # - # Post.find(:all, :include => :approved_comments) + # Post.all(:include => :approved_comments) # # This will load posts and eager load the +approved_comments+ association, which contains # only those comments that have been approved. @@ -745,7 +745,7 @@ module ActiveRecord # # A call that tries to eager load the addressable model # - # Address.find(:all, :include => :addressable) + # Address.all(:include => :addressable) # # This will execute one query to load the addresses and load the addressables with one # query per addressable type. @@ -763,33 +763,33 @@ module ActiveRecord # second time, the table is aliased as #{reflection_name}_#{parent_table_name}. # Indexes are appended for any more successive uses of the table name. # - # Post.find :all, :joins => :comments + # Post.all :joins => :comments # # => SELECT ... FROM posts INNER JOIN comments ON ... - # Post.find :all, :joins => :special_comments # STI + # Post.all :joins => :special_comments # STI # # => SELECT ... FROM posts INNER JOIN comments ON ... AND comments.type = 'SpecialComment' - # Post.find :all, :joins => [:comments, :special_comments] # special_comments is the reflection name, posts is the parent table name + # Post.all :joins => [:comments, :special_comments] # special_comments is the reflection name, posts is the parent table name # # => SELECT ... FROM posts INNER JOIN comments ON ... INNER JOIN comments special_comments_posts # # Acts as tree example: # - # TreeMixin.find :all, :joins => :children + # TreeMixin.all :joins => :children # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... - # TreeMixin.find :all, :joins => {:children => :parent} + # TreeMixin.all :joins => {:children => :parent} # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... # INNER JOIN parents_mixins ... - # TreeMixin.find :all, :joins => {:children => {:parent => :children}} + # TreeMixin.all :joins => {:children => {:parent => :children}} # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... # INNER JOIN parents_mixins ... # INNER JOIN mixins childrens_mixins_2 # # Has and Belongs to Many join tables use the same idea, but add a _join suffix: # - # Post.find :all, :joins => :categories + # Post.all :joins => :categories # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... - # Post.find :all, :joins => {:categories => :posts} + # Post.all :joins => {:categories => :posts} # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... # INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories - # Post.find :all, :joins => {:categories => {:posts => :categories}} + # Post.all :joins => {:categories => {:posts => :categories}} # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... # INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories # INNER JOIN categories_posts categories_posts_join INNER JOIN categories categories_posts_2 @@ -797,9 +797,9 @@ module ActiveRecord # If you wish to specify your own custom joins using a :joins option, those table # names will take precedence over the eager associations: # - # Post.find :all, :joins => :comments, :joins => "inner join comments ..." + # Post.all :joins => :comments, :joins => "inner join comments ..." # # => SELECT ... FROM posts INNER JOIN comments_posts ON ... INNER JOIN comments ... - # Post.find :all, :joins => [:comments, :special_comments], :joins => "inner join comments ..." + # Post.all :joins => [:comments, :special_comments], :joins => "inner join comments ..." # # => SELECT ... FROM posts INNER JOIN comments comments_posts ON ... # INNER JOIN comments special_comments_posts ... # INNER JOIN comments ... @@ -1031,7 +1031,7 @@ module ActiveRecord # === Example # # Example: A Firm class declares has_many :clients, which will add: - # * Firm#clients (similar to Clients.find :all, :conditions => ["firm_id = ?", id]) + # * Firm#clients (similar to Clients.all :conditions => ["firm_id = ?", id]) # * Firm#clients<< # * Firm#clients.delete # * Firm#clients= diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index ea1709cb1f..3bd2ed8f1b 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -87,7 +87,7 @@ module ActiveRecord # # For example, in # - # Location.find :all, :conditions => ["lat = ? AND lng = ?", 53.7362] + # Location.all :conditions => ["lat = ? AND lng = ?", 53.7362] # # two placeholders are given but only one variable to fill them. class PreparedStatementInvalid < ActiveRecordError diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 819743a361..3f36dcde14 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -149,13 +149,13 @@ class FixturesFileNotFound < StandardError; end # self.use_transactional_fixtures = true # # test "godzilla" do -# assert !Foo.find(:all).empty? +# assert !Foo.all.empty? # Foo.destroy_all -# assert Foo.find(:all).empty? +# assert Foo.all.empty? # end # # test "godzilla aftermath" do -# assert !Foo.find(:all).empty? +# assert !Foo.all.empty? # end # end # -- cgit v1.2.3 From 6c94f6967364365bf7032f80a10ed1aa5d5035ce Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 8 Jul 2011 01:24:00 +0900 Subject: find(:first) => first --- activerecord/lib/active_record/associations.rb | 10 +++++----- .../lib/active_record/associations/collection_proxy.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index b23b51e832..d489dadb4d 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -420,7 +420,7 @@ module ActiveRecord # end # end # - # person = Account.find(:first).people.find_or_create_by_name("David Heinemeier Hansson") + # person = Account.first.people.find_or_create_by_name("David Heinemeier Hansson") # person.first_name # => "David" # person.last_name # => "Heinemeier Hansson" # @@ -477,7 +477,7 @@ module ActiveRecord # belongs_to :book # end # - # @author = Author.find :first + # @author = Author.first # @author.authorships.collect { |a| a.book } # selects all books that the author's authorships belong to # @author.books # selects all books by using the Authorship join model # @@ -497,7 +497,7 @@ module ActiveRecord # belongs_to :client # end # - # @firm = Firm.find :first + # @firm = Firm.first # @firm.clients.collect { |c| c.invoices }.flatten # select all invoices for all clients of the firm # @firm.invoices # selects all invoices by going through the Client join model # @@ -732,7 +732,7 @@ module ActiveRecord # has_many :most_recent_comments, :class_name => 'Comment', :order => 'id DESC', :limit => 10 # end # - # Picture.find(:first, :include => :most_recent_comments).most_recent_comments # => returns all associated comments. + # Picture.first(:include => :most_recent_comments).most_recent_comments # => returns all associated comments. # # When eager loaded, conditions are interpolated in the context of the model class, not # the model instance. Conditions are lazily interpolated before the actual model exists. @@ -1195,7 +1195,7 @@ module ActiveRecord # === Example # # An Account class declares has_one :beneficiary, which will add: - # * Account#beneficiary (similar to Beneficiary.find(:first, :conditions => "account_id = #{id}")) + # * Account#beneficiary (similar to Beneficiary.first(:conditions => "account_id = #{id}")) # * Account#beneficiary=(beneficiary) (similar to beneficiary.account_id = account.id; beneficiary.save) # * Account#build_beneficiary (similar to Beneficiary.new("account_id" => id)) # * Account#create_beneficiary (similar to b = Beneficiary.new("account_id" => id); b.save; b) diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 7f7dec467a..827dfb7ccb 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -12,7 +12,7 @@ module ActiveRecord # has_many :posts # end # - # blog = Blog.find(:first) + # blog = Blog.first # # the association proxy in blog.posts has the object in +blog+ as # @owner, the collection of its posts as @target, and -- cgit v1.2.3 From c4bd47778fb848fad004d7fa94c83eac8c00e39d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 8 Jul 2011 01:49:34 +0900 Subject: :include => includes --- activerecord/lib/active_record/associations.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index d489dadb4d..49e3a379d4 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -669,7 +669,7 @@ module ActiveRecord # To iterate over these one hundred posts, we'll generate 201 database queries. Let's # first just optimize it for retrieving the author: # - # Post.all(:include => :author).each do |post| + # Post.includes(:author).each do |post| # # This references the name of the +belongs_to+ association that also used the :author # symbol. After loading the posts, find will collect the +author_id+ from each one and load @@ -678,7 +678,7 @@ module ActiveRecord # # We can improve upon the situation further by referencing both associations in the finder with: # - # Post.all(:include => [ :author, :comments ]).each do |post| + # Post.includes(:author, :comments).each do |post| # # This will load all comments with a single query. This reduces the total number of queries # to 3. More generally the number of queries will be 1 plus the number of associations @@ -686,7 +686,7 @@ module ActiveRecord # # To include a deep hierarchy of associations, use a hash: # - # Post.all(:include => [ :author, { :comments => { :author => :gravatar } } ]).each do |post| + # Post.includes(:author, {:comments => {:author => :gravatar}}).each do |post| # # That'll grab not only all the comments but all their authors and gravatar pictures. # You can mix and match symbols, arrays and hashes in any combination to describe the @@ -714,13 +714,13 @@ module ActiveRecord # :order => "author.name DESC" will work but :order => "name DESC" will not. # # If you do want eager load only some members of an association it is usually more natural - # to :include an association which has conditions defined on it: + # to include an association which has conditions defined on it: # # class Post < ActiveRecord::Base # has_many :approved_comments, :class_name => 'Comment', :conditions => ['approved = ?', true] # end # - # Post.all(:include => :approved_comments) + # Post.includes(:approved_comments) # # This will load posts and eager load the +approved_comments+ association, which contains # only those comments that have been approved. @@ -732,7 +732,7 @@ module ActiveRecord # has_many :most_recent_comments, :class_name => 'Comment', :order => 'id DESC', :limit => 10 # end # - # Picture.first(:include => :most_recent_comments).most_recent_comments # => returns all associated comments. + # Picture.includes(:most_recent_comments).first.most_recent_comments # => returns all associated comments. # # When eager loaded, conditions are interpolated in the context of the model class, not # the model instance. Conditions are lazily interpolated before the actual model exists. @@ -745,7 +745,7 @@ module ActiveRecord # # A call that tries to eager load the addressable model # - # Address.all(:include => :addressable) + # Address.includes(:addressable) # # This will execute one query to load the addresses and load the addressables with one # query per addressable type. -- cgit v1.2.3 From b2816ae97173839176ccb982b3dc48854f1fc280 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 8 Jul 2011 05:47:14 +0900 Subject: :joins => joins --- activerecord/lib/active_record/associations.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 49e3a379d4..029d7a9b15 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -763,43 +763,43 @@ module ActiveRecord # second time, the table is aliased as #{reflection_name}_#{parent_table_name}. # Indexes are appended for any more successive uses of the table name. # - # Post.all :joins => :comments + # Post.joins(:comments) # # => SELECT ... FROM posts INNER JOIN comments ON ... - # Post.all :joins => :special_comments # STI + # Post.joins(:special_comments) # STI # # => SELECT ... FROM posts INNER JOIN comments ON ... AND comments.type = 'SpecialComment' - # Post.all :joins => [:comments, :special_comments] # special_comments is the reflection name, posts is the parent table name + # Post.joins(:comments, :special_comments) # special_comments is the reflection name, posts is the parent table name # # => SELECT ... FROM posts INNER JOIN comments ON ... INNER JOIN comments special_comments_posts # # Acts as tree example: # - # TreeMixin.all :joins => :children + # TreeMixin.joins(:children) # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... - # TreeMixin.all :joins => {:children => :parent} + # TreeMixin.joins(:children => :parent) # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... # INNER JOIN parents_mixins ... - # TreeMixin.all :joins => {:children => {:parent => :children}} + # TreeMixin.joins(:children => {:parent => :children}) # # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... # INNER JOIN parents_mixins ... # INNER JOIN mixins childrens_mixins_2 # # Has and Belongs to Many join tables use the same idea, but add a _join suffix: # - # Post.all :joins => :categories + # Post.joins(:categories) # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... - # Post.all :joins => {:categories => :posts} + # Post.joins(:categories => :posts) # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... # INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories - # Post.all :joins => {:categories => {:posts => :categories}} + # Post.joins(:categories => {:posts => :categories}) # # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ... # INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories # INNER JOIN categories_posts categories_posts_join INNER JOIN categories categories_posts_2 # - # If you wish to specify your own custom joins using a :joins option, those table + # If you wish to specify your own custom joins using joins method, those table # names will take precedence over the eager associations: # - # Post.all :joins => :comments, :joins => "inner join comments ..." + # Post.joins(:comments).joins("inner join comments ...") # # => SELECT ... FROM posts INNER JOIN comments_posts ON ... INNER JOIN comments ... - # Post.all :joins => [:comments, :special_comments], :joins => "inner join comments ..." + # Post.joins(:comments, :special_comments).joins("inner join comments ...") # # => SELECT ... FROM posts INNER JOIN comments comments_posts ON ... # INNER JOIN comments special_comments_posts ... # INNER JOIN comments ... -- cgit v1.2.3 From 4d4819fb279386570466b2f99254cd77fb71e05c Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 8 Jul 2011 06:05:48 +0900 Subject: :conditions => where --- activerecord/lib/active_record/errors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 3bd2ed8f1b..ad7d8cd63c 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -87,7 +87,7 @@ module ActiveRecord # # For example, in # - # Location.all :conditions => ["lat = ? AND lng = ?", 53.7362] + # Location.where("lat = ? AND lng = ?", 53.7362) # # two placeholders are given but only one variable to fill them. class PreparedStatementInvalid < ActiveRecordError -- cgit v1.2.3