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.rb37
1 files changed, 24 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index c50750352f..07dc28ddff 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -131,9 +131,7 @@ module ActiveRecord
# class Account < ActiveRecord::Base
# has_many :people do
# def find_or_create_by_name(name)
- # first_name, *last_name = name.split
- # last_name = last_name.join " "
- #
+ # first_name, last_name = name.split(" ", 2)
# find_or_create_by_first_name_and_last_name(first_name, last_name)
# end
# end
@@ -147,9 +145,7 @@ module ActiveRecord
#
# module FindOrCreateByNameExtension
# def find_or_create_by_name(name)
- # first_name, *last_name = name.split
- # last_name = last_name.join " "
- #
+ # first_name, last_name = name.split(" ", 2)
# find_or_create_by_first_name_and_last_name(first_name, last_name)
# end
# end
@@ -330,6 +326,11 @@ module ActiveRecord
# 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.
+ # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
+ # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned.
+ # * <tt>:offset</tt>: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
+ # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not
+ # include the joined columns.
#
# Option examples:
# has_many :comments, :order => "posted_on"
@@ -591,6 +592,11 @@ module ActiveRecord
# 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.
+ # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
+ # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned.
+ # * <tt>:offset</tt>: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
+ # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not
+ # include the joined columns.
#
# Option examples:
# has_and_belongs_to_many :projects
@@ -872,10 +878,13 @@ module ActiveRecord
def create_has_many_reflection(association_id, options, &extension)
options.assert_valid_keys(
- :foreign_key, :class_name, :exclusively_dependent, :dependent,
- :conditions, :order, :include, :finder_sql, :counter_sql,
- :before_add, :after_add, :before_remove, :after_remove, :extend,
- :group, :as, :through
+ :class_name, :table_name, :foreign_key,
+ :exclusively_dependent, :dependent,
+ :select, :conditions, :include, :order, :group, :limit, :offset,
+ :as, :through,
+ :finder_sql, :counter_sql,
+ :before_add, :after_add, :before_remove, :after_remove,
+ :extend
)
options[:extend] = create_extension_module(association_id, extension) if block_given?
@@ -916,9 +925,11 @@ module ActiveRecord
def create_has_and_belongs_to_many_reflection(association_id, options, &extension)
options.assert_valid_keys(
- :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
+ :class_name, :table_name, :join_table, :foreign_key, :association_foreign_key,
+ :select, :conditions, :include, :order, :group, :limit, :offset,
+ :finder_sql, :delete_sql, :insert_sql, :uniq,
+ :before_add, :after_add, :before_remove, :after_remove,
+ :extend
)
options[:extend] = create_extension_module(association_id, extension) if block_given?