From 6727e3c9e7eca006e5221739dc72694d2c1e024d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 30 Jun 2012 14:18:31 -0500 Subject: update AR::SchemaStatements#column_exists? documentation [ci skip] --- .../active_record/connection_adapters/abstract/schema_statements.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index f5794a4e54..50da373c6a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -57,7 +57,6 @@ module ActiveRecord # Checks to see if a column exists in a given table. # - # === Examples # # Check a column exists # column_exists?(:suppliers, :name) # @@ -65,7 +64,10 @@ module ActiveRecord # column_exists?(:suppliers, :name, :string) # # # Check a column exists with a specific definition - # column_exists?(:suppliers, :name, :string, :limit => 100) + # column_exists?(:suppliers, :name, :string, limit: 100) + # column_exists?(:suppliers, :name, :string, default: 'default' + # column_exists?(:suppliers, :name, :string, null: false) + # column_exists?(:suppliers, :tax, :decimal, precision: 8, scale: 2) def column_exists?(table_name, column_name, type = nil, options = {}) columns(table_name).any?{ |c| c.name == column_name.to_s && (!type || c.type == type) && -- cgit v1.2.3 From 9b45f0fb712ec1b649b8d482f9552a41ed5e19e2 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 30 Jun 2012 14:26:19 -0500 Subject: =?UTF-8?q?fix=20AR::SchemaStatements#column=5Fexists=3F=20example?= =?UTF-8?q?=C2=A0[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/active_record/connection_adapters/abstract/schema_statements.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 50da373c6a..2f796861a8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -65,7 +65,7 @@ module ActiveRecord # # # Check a column exists with a specific definition # column_exists?(:suppliers, :name, :string, limit: 100) - # column_exists?(:suppliers, :name, :string, default: 'default' + # column_exists?(:suppliers, :name, :string, default: 'default') # column_exists?(:suppliers, :name, :string, null: false) # column_exists?(:suppliers, :tax, :decimal, precision: 8, scale: 2) def column_exists?(table_name, column_name, type = nil, options = {}) -- cgit v1.2.3 From 62463d11b8ecb9fe5987776e58eee644c0ad96b2 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 1 Jul 2012 15:53:27 -0500 Subject: remove :nodoc: of AR::Scoping#unscoped [ci skip] --- activerecord/lib/active_record/scoping/default.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index af51c803a7..b35fec7920 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -31,14 +31,14 @@ module ActiveRecord # Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10" # } # - # It is recommended that you use the block form of unscoped because chaining - # unscoped with scope does not work. Assuming that + # It is recommended that you use the block form of unscoped because + # chaining unscoped with scope does not work. Assuming that # published is a scope, the following two statements - # are equal: the default_scope is applied on both. + # are equal: the default_scope is applied on both. # # Post.unscoped.published # Post.published - def unscoped #:nodoc: + def unscoped block_given? ? relation.scoping { yield } : relation end -- cgit v1.2.3 From d203a0e0b4f2a1959fb3dc486a5ee6684b44ccb3 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 5 Jul 2012 18:43:48 -0700 Subject: Add documentation for includes --- activerecord/lib/active_record/relation/query_methods.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 6f49548aab..51d21121c8 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -41,6 +41,17 @@ module ActiveRecord alias extensions extending_values + # Specify relationships to be included in the result set. For + # example: + # + # users = User.includes(:address) + # users.each do |user| + # user.address.city + # end + # + # allows you to access the +address+ attribute of the +User+ model without + # firing an additional query. This will often result in a + # performance improvement over a simple +join+ def includes(*args) args.empty? ? self : spawn.includes!(*args) end -- cgit v1.2.3 From d7a2309fe39d3807c1c97de116b23d6bb2c08d79 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 5 Jul 2012 19:01:00 -0700 Subject: Add group documentation --- activerecord/lib/active_record/relation/query_methods.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 51d21121c8..1636e49065 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -142,6 +142,18 @@ module ActiveRecord self end + # Allows to specify a group attribute: + # + # User.group(:name) + # => SELECT "users".* FROM "users" GROUP BY name + # + # Returns an array with uniq records based on the `group` attribute: + # + # User.select([:id, :name]) + # => [#, #, # + # + # User.group(:name) + # => [#, #] def group(*args) args.blank? ? self : spawn.group!(*args) end -- cgit v1.2.3 From ad919087a4a816514a0a040ab9e2045e269a241f Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 5 Jul 2012 19:02:58 -0700 Subject: Add order docs --- activerecord/lib/active_record/relation/query_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1636e49065..94843dd2c6 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -165,6 +165,16 @@ module ActiveRecord self end + # Allows to specify an order attribute: + # + # User.order('name') + # => SELECT "users".* FROM "users" ORDER BY name + # + # User.order('name DESC') + # => SELECT "users".* FROM "users" ORDER BY name DESC + # + # User.order('name DESC, email') + # => SELECT "users".* FROM "users" ORDER BY name DESC, email def order(*args) args.blank? ? self : spawn.order!(*args) end -- cgit v1.2.3 From c47a698d5d497340d4e349257522212173865838 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Fri, 6 Jul 2012 18:50:53 -0700 Subject: Add nodoc to relation methods --- .../lib/active_record/relation/query_methods.rb | 46 +++++++++++----------- 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 94843dd2c6..2d2e755fee 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -35,7 +35,7 @@ module ActiveRecord CODE end - def create_with_value + def create_with_value #:nodoc: @values[:create_with] || {} end @@ -56,7 +56,7 @@ module ActiveRecord args.empty? ? self : spawn.includes!(*args) end - def includes!(*args) + def includes!(*args) #:nodoc: args.reject! {|a| a.blank? } self.includes_values = (includes_values + args).flatten.uniq @@ -67,7 +67,7 @@ module ActiveRecord args.blank? ? self : spawn.eager_load!(*args) end - def eager_load!(*args) + def eager_load!(*args) #:nodoc: self.eager_load_values += args self end @@ -76,7 +76,7 @@ module ActiveRecord args.blank? ? self : spawn.preload!(*args) end - def preload!(*args) + def preload!(*args) #:nodoc: self.preload_values += args self end @@ -93,7 +93,7 @@ module ActiveRecord args.blank? ? self : spawn.references!(*args) end - def references!(*args) + def references!(*args) #:nodoc: args.flatten! self.references_values = (references_values + args.map!(&:to_s)).uniq @@ -137,7 +137,7 @@ module ActiveRecord end end - def select!(value) + def select!(value) #:nodoc: self.select_values += Array.wrap(value) self end @@ -158,7 +158,7 @@ module ActiveRecord args.blank? ? self : spawn.group!(*args) end - def group!(*args) + def group!(*args) #:nodoc: args.flatten! self.group_values += args @@ -179,7 +179,7 @@ module ActiveRecord args.blank? ? self : spawn.order!(*args) end - def order!(*args) + def order!(*args) #:nodoc: args.flatten! references = args.reject { |arg| Arel::Node === arg } @@ -203,7 +203,7 @@ module ActiveRecord args.blank? ? self : spawn.reorder!(*args) end - def reorder!(*args) + def reorder!(*args) #:nodoc: args.flatten! self.reordering_value = true @@ -215,7 +215,7 @@ module ActiveRecord args.compact.blank? ? self : spawn.joins!(*args) end - def joins!(*args) + def joins!(*args) #:nodoc: args.flatten! self.joins_values += args @@ -226,7 +226,7 @@ module ActiveRecord spawn.bind!(value) end - def bind!(value) + def bind!(value) #:nodoc: self.bind_values += [value] self end @@ -325,9 +325,7 @@ module ActiveRecord opts.blank? ? self : spawn.where!(opts, *rest) end - # #where! is identical to #where, except that instead of returning a new relation, it adds - # the condition to the existing relation. - def where!(opts, *rest) + def where!(opts, *rest) #:nodoc: references!(PredicateBuilder.references(opts)) if Hash === opts self.where_values += build_where(opts, rest) @@ -338,7 +336,7 @@ module ActiveRecord opts.blank? ? self : spawn.having!(opts, *rest) end - def having!(opts, *rest) + def having!(opts, *rest) #:nodoc: references!(PredicateBuilder.references(opts)) if Hash === opts self.having_values += build_where(opts, rest) @@ -354,7 +352,7 @@ module ActiveRecord spawn.limit!(value) end - def limit!(value) + def limit!(value) #:nodoc: self.limit_value = value self end @@ -370,7 +368,7 @@ module ActiveRecord spawn.offset!(value) end - def offset!(value) + def offset!(value) #:nodoc: self.offset_value = value self end @@ -379,7 +377,7 @@ module ActiveRecord spawn.lock!(locks) end - def lock!(locks = true) + def lock!(locks = true) #:nodoc: case locks when String, TrueClass, NilClass self.lock_value = locks || true @@ -427,7 +425,7 @@ module ActiveRecord spawn.readonly!(value) end - def readonly!(value = true) + def readonly!(value = true) #:nodoc: self.readonly_value = value self end @@ -436,7 +434,7 @@ module ActiveRecord spawn.create_with!(value) end - def create_with!(value) + def create_with!(value) #:nodoc: self.create_with_value = value ? create_with_value.merge(value) : {} self end @@ -458,7 +456,7 @@ module ActiveRecord spawn.from!(value, subquery_name) end - def from!(value, subquery_name = nil) + def from!(value, subquery_name = nil) #:nodoc: self.from_value = [value, subquery_name] self end @@ -477,7 +475,7 @@ module ActiveRecord spawn.uniq!(value) end - def uniq!(value = true) + def uniq!(value = true) #:nodoc: self.uniq_value = value self end @@ -526,7 +524,7 @@ module ActiveRecord end end - def extending!(*modules, &block) + def extending!(*modules, &block) #:nodoc: modules << Module.new(&block) if block_given? self.extending_values = modules.flatten @@ -542,7 +540,7 @@ module ActiveRecord spawn.reverse_order! end - def reverse_order! + def reverse_order! #:nodoc: self.reverse_order_value = !reverse_order_value self end -- cgit v1.2.3 From f7562c0c357b483f414435f56abba1e6249036d2 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 Jul 2012 20:42:22 +0530 Subject: Revert "Add nodoc to relation methods" This reverts commit c47a698d5d497340d4e349257522212173865838. Reason: Let's revert pending further discussions --- .../lib/active_record/relation/query_methods.rb | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 2d2e755fee..94843dd2c6 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -35,7 +35,7 @@ module ActiveRecord CODE end - def create_with_value #:nodoc: + def create_with_value @values[:create_with] || {} end @@ -56,7 +56,7 @@ module ActiveRecord args.empty? ? self : spawn.includes!(*args) end - def includes!(*args) #:nodoc: + def includes!(*args) args.reject! {|a| a.blank? } self.includes_values = (includes_values + args).flatten.uniq @@ -67,7 +67,7 @@ module ActiveRecord args.blank? ? self : spawn.eager_load!(*args) end - def eager_load!(*args) #:nodoc: + def eager_load!(*args) self.eager_load_values += args self end @@ -76,7 +76,7 @@ module ActiveRecord args.blank? ? self : spawn.preload!(*args) end - def preload!(*args) #:nodoc: + def preload!(*args) self.preload_values += args self end @@ -93,7 +93,7 @@ module ActiveRecord args.blank? ? self : spawn.references!(*args) end - def references!(*args) #:nodoc: + def references!(*args) args.flatten! self.references_values = (references_values + args.map!(&:to_s)).uniq @@ -137,7 +137,7 @@ module ActiveRecord end end - def select!(value) #:nodoc: + def select!(value) self.select_values += Array.wrap(value) self end @@ -158,7 +158,7 @@ module ActiveRecord args.blank? ? self : spawn.group!(*args) end - def group!(*args) #:nodoc: + def group!(*args) args.flatten! self.group_values += args @@ -179,7 +179,7 @@ module ActiveRecord args.blank? ? self : spawn.order!(*args) end - def order!(*args) #:nodoc: + def order!(*args) args.flatten! references = args.reject { |arg| Arel::Node === arg } @@ -203,7 +203,7 @@ module ActiveRecord args.blank? ? self : spawn.reorder!(*args) end - def reorder!(*args) #:nodoc: + def reorder!(*args) args.flatten! self.reordering_value = true @@ -215,7 +215,7 @@ module ActiveRecord args.compact.blank? ? self : spawn.joins!(*args) end - def joins!(*args) #:nodoc: + def joins!(*args) args.flatten! self.joins_values += args @@ -226,7 +226,7 @@ module ActiveRecord spawn.bind!(value) end - def bind!(value) #:nodoc: + def bind!(value) self.bind_values += [value] self end @@ -325,7 +325,9 @@ module ActiveRecord opts.blank? ? self : spawn.where!(opts, *rest) end - def where!(opts, *rest) #:nodoc: + # #where! is identical to #where, except that instead of returning a new relation, it adds + # the condition to the existing relation. + def where!(opts, *rest) references!(PredicateBuilder.references(opts)) if Hash === opts self.where_values += build_where(opts, rest) @@ -336,7 +338,7 @@ module ActiveRecord opts.blank? ? self : spawn.having!(opts, *rest) end - def having!(opts, *rest) #:nodoc: + def having!(opts, *rest) references!(PredicateBuilder.references(opts)) if Hash === opts self.having_values += build_where(opts, rest) @@ -352,7 +354,7 @@ module ActiveRecord spawn.limit!(value) end - def limit!(value) #:nodoc: + def limit!(value) self.limit_value = value self end @@ -368,7 +370,7 @@ module ActiveRecord spawn.offset!(value) end - def offset!(value) #:nodoc: + def offset!(value) self.offset_value = value self end @@ -377,7 +379,7 @@ module ActiveRecord spawn.lock!(locks) end - def lock!(locks = true) #:nodoc: + def lock!(locks = true) case locks when String, TrueClass, NilClass self.lock_value = locks || true @@ -425,7 +427,7 @@ module ActiveRecord spawn.readonly!(value) end - def readonly!(value = true) #:nodoc: + def readonly!(value = true) self.readonly_value = value self end @@ -434,7 +436,7 @@ module ActiveRecord spawn.create_with!(value) end - def create_with!(value) #:nodoc: + def create_with!(value) self.create_with_value = value ? create_with_value.merge(value) : {} self end @@ -456,7 +458,7 @@ module ActiveRecord spawn.from!(value, subquery_name) end - def from!(value, subquery_name = nil) #:nodoc: + def from!(value, subquery_name = nil) self.from_value = [value, subquery_name] self end @@ -475,7 +477,7 @@ module ActiveRecord spawn.uniq!(value) end - def uniq!(value = true) #:nodoc: + def uniq!(value = true) self.uniq_value = value self end @@ -524,7 +526,7 @@ module ActiveRecord end end - def extending!(*modules, &block) #:nodoc: + def extending!(*modules, &block) modules << Module.new(&block) if block_given? self.extending_values = modules.flatten @@ -540,7 +542,7 @@ module ActiveRecord spawn.reverse_order! end - def reverse_order! #:nodoc: + def reverse_order! self.reverse_order_value = !reverse_order_value self end -- cgit v1.2.3 From 700e5ffea261de09c6e12b5077597320ba1ffbd1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 Jul 2012 20:43:48 +0530 Subject: minor text change [ci skip] --- activerecord/lib/active_record/relation/query_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 94843dd2c6..e401ed37b0 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -147,7 +147,7 @@ module ActiveRecord # User.group(:name) # => SELECT "users".* FROM "users" GROUP BY name # - # Returns an array with uniq records based on the `group` attribute: + # Returns an array with distinct records based on the `group` attribute: # # User.select([:id, :name]) # => [#, #, # -- cgit v1.2.3