From 91c8d91536b1f41f0c4518e67b4bf31b1ef4f109 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Sat, 7 Jul 2012 10:20:22 -0700 Subject: Add docs for eager_laod and preload --- activerecord/lib/active_record/relation/query_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index e401ed37b0..74ffa09c85 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -63,6 +63,12 @@ module ActiveRecord self end + # Forces eager loading by performing a LEFT OUTER JOIN on +args+: + # + # User.eager_load(:posts) + # => SELECT "users"."id" AS t0_r0, "users"."name" AS t0_r1, ... + # FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = + # "users"."id" def eager_load(*args) args.blank? ? self : spawn.eager_load!(*args) end @@ -72,6 +78,10 @@ module ActiveRecord self end + # Allows preloading of +args+, in the same way that +includes+ does: + # + # User.preload(:posts) + # => SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1, 2, 3) def preload(*args) args.blank? ? self : spawn.preload!(*args) end -- cgit v1.2.3 From 8e7470adcbce7c278f668ea671dfbcaf089114eb Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Sat, 7 Jul 2012 11:36:03 -0700 Subject: Add doc for joins and improve includes doc --- .../lib/active_record/relation/query_methods.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 74ffa09c85..00030b9e1f 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -51,7 +51,18 @@ module ActiveRecord # # 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+ + # performance improvement over a simple +join+. + # + # === conditions + # + # If you want to add conditions to your included models you'll have + # to explicitly reference them. For example: + # + # User.includes(:posts).where('posts.name = ?', 'example') + # + # Will throw an error, but this will work: + # + # User.includes(:posts).where('posts.name = ?', 'example').references(:posts) def includes(*args) args.empty? ? self : spawn.includes!(*args) end @@ -157,7 +168,7 @@ module ActiveRecord # User.group(:name) # => SELECT "users".* FROM "users" GROUP BY name # - # Returns an array with distinct records based on the `group` attribute: + # Returns an array with distinct records based on the +group+ attribute: # # User.select([:id, :name]) # => [#, #, # @@ -221,6 +232,10 @@ module ActiveRecord self end + # Performs a joins on +args+: + # + # User.joins(:posts) + # => SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id" def joins(*args) args.compact.blank? ? self : spawn.joins!(*args) end -- cgit v1.2.3 From e68f63e6048aae61954904125b33e02a6c8934e5 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Sat, 7 Jul 2012 13:53:38 -0700 Subject: Add docs for having, lock and readonly --- activerecord/lib/active_record/relation/query_methods.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 00030b9e1f..57f80d383e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -359,6 +359,10 @@ module ActiveRecord self end + # Allows to specify a HAVING clause. Note that you can't use HAVING + # without also specifying a GROUP clause. + # + # Order.having('SUM(price) > 30').group('user_id') def having(opts, *rest) opts.blank? ? self : spawn.having!(opts, *rest) end @@ -400,6 +404,8 @@ module ActiveRecord self end + # Specifies locking settings (default to +true+). For more information + # on locking, please see +ActiveRecord::Locking+. def lock(locks = true) spawn.lock!(locks) end @@ -448,6 +454,12 @@ module ActiveRecord scoped.extending(NullRelation) end + # Sets readonly attributes for the returned relation. If value is + # true (default), attempting to update a record will result in an error. + # + # users = User.readonly + # users.first.save + # => ActiveRecord::ReadOnlyRecord: ActiveRecord::ReadOnlyRecord def readonly(value = true) spawn.readonly!(value) end -- cgit v1.2.3 From 92dcdc590ebb8407e7f53c26d501d169799d0eff Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 15 Jul 2012 02:56:08 +0900 Subject: session_id column is string in default --- activerecord/lib/active_record/session_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 5a256b040b..51f4a91069 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -7,7 +7,7 @@ module ActiveRecord # # The default assumes a +sessions+ tables with columns: # +id+ (numeric primary key), - # +session_id+ (text, or longtext if your session data exceeds 65K), and + # +session_id+ (string, usually varchar; maximum length is 255), and # +data+ (text or longtext; careful if your session data exceeds 65KB). # # The +session_id+ column should always be indexed for speedy lookups. -- cgit v1.2.3