aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 45d23eac1d..ff6775e027 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -323,9 +323,11 @@ module ActiveRecord
# * <tt>:counter_sql</tt> - specify a complete SQL statement to fetch the size of the association. If +:finder_sql+ is
# specified but +:counter_sql+, +:counter_sql+ will be generated by replacing SELECT ... FROM with SELECT COUNT(*) FROM.
# * <tt>:extend</tt> - specify a named module for extending the proxy, see "Association extensions".
+ # * <tt>:include</tt> - specify second-order associations that should be eager loaded when the collection is loaded.
#
# Option examples:
# has_many :comments, :order => "posted_on"
+ # has_many :comments, :include => :author
# has_many :people, :class_name => "Person", :conditions => "deleted = 0", :order => "name"
# has_many :tracks, :order => "position", :dependent => true
# has_many :subscribers, :class_name => "Person", :finder_sql =>
@@ -336,7 +338,7 @@ module ActiveRecord
def has_many(association_id, options = {}, &extension)
options.assert_valid_keys(
:foreign_key, :class_name, :exclusively_dependent, :dependent,
- :conditions, :order, :finder_sql, :counter_sql,
+ :conditions, :order, :include, :finder_sql, :counter_sql,
:before_add, :after_add, :before_remove, :after_remove, :extend
)
@@ -417,13 +419,14 @@ module ActiveRecord
# * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name
# of this class in lower-case and "_id" suffixed. So a +Person+ class that makes a has_one association will use "person_id"
# as the default foreign_key.
+ # * <tt>:include</tt> - specify second-order associations that should be eager loaded when this object is loaded.
#
# Option examples:
# has_one :credit_card, :dependent => true
# has_one :last_comment, :class_name => "Comment", :order => "posted_on"
# has_one :project_manager, :class_name => "Person", :conditions => "role = 'project_manager'"
def has_one(association_id, options = {})
- options.assert_valid_keys(:class_name, :foreign_key, :remote, :conditions, :order, :dependent, :counter_cache, :extend)
+ options.assert_valid_keys(:class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend)
association_name, association_class_name, association_class_primary_key_name =
associate_identification(association_id, options[:class_name], options[:foreign_key], false)
@@ -496,6 +499,7 @@ module ActiveRecord
# and decrement_counter. The counter cache is incremented when an object of this class is created and decremented when it's
# destroyed. This requires that a column named "#{table_name}_count" (such as comments_count for a belonging Comment class)
# is used on the associate class (such as a Post class).
+ # * <tt>:include</tt> - specify second-order associations that should be eager loaded when this object is loaded.
#
# Option examples:
# belongs_to :firm, :foreign_key => "client_of"
@@ -503,7 +507,7 @@ module ActiveRecord
# belongs_to :valid_coupon, :class_name => "Coupon", :foreign_key => "coupon_id",
# :conditions => 'discounts > #{payments_count}'
def belongs_to(association_id, options = {})
- options.assert_valid_keys(:class_name, :foreign_key, :remote, :conditions, :order, :dependent, :counter_cache, :extend)
+ options.assert_valid_keys(:class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend)
association_name, association_class_name, class_primary_key_name =
associate_identification(association_id, options[:class_name], options[:foreign_key], false)
@@ -613,16 +617,18 @@ module ActiveRecord
# * <tt>:insert_sql</tt> - overwrite the default generated SQL used to add links between the associated classes
# with a manual one
# * <tt>:extend</tt> - anonymous module for extending the proxy, see "Association extensions".
+ # * <tt>:include</tt> - specify second-order associations that should be eager loaded when the collection is loaded.
#
# Option examples:
# has_and_belongs_to_many :projects
+ # has_and_belongs_to_many :projects, :include => [ :milestones, :manager ]
# has_and_belongs_to_many :nations, :class_name => "Country"
# has_and_belongs_to_many :categories, :join_table => "prods_cats"
# has_and_belongs_to_many :active_projects, :join_table => 'developers_projects', :delete_sql =>
# 'DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}'
def has_and_belongs_to_many(association_id, options = {}, &extension)
options.assert_valid_keys(
- :class_name, :table_name, :foreign_key, :association_foreign_key, :conditions,
+ :class_name, :table_name, :foreign_key, :association_foreign_key, :conditions, :include,
:join_table, :finder_sql, :delete_sql, :insert_sql, :order, :uniq, :before_add, :after_add,
:before_remove, :after_remove, :extend
)