aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAlan Larkin <alan.larkin@gmail.com>2011-08-20 13:12:10 +0100
committerAlan Larkin <alan.larkin@gmail.com>2011-08-20 19:42:07 +0100
commitdbe9a9b48280e3210f6c42789c3a2980b72febf4 (patch)
tree3d2a23f8ea9c32de7b2ae24fd3f111ddf6f597e0 /activerecord
parent8bd76aa50ec5dc5da3c398a0fd5dc971f64d8d68 (diff)
downloadrails-dbe9a9b48280e3210f6c42789c3a2980b72febf4.tar.gz
rails-dbe9a9b48280e3210f6c42789c3a2980b72febf4.tar.bz2
rails-dbe9a9b48280e3210f6c42789c3a2980b72febf4.zip
Updated the docs for the has_many :finder_sql option to reflect changes made in #a7e19b30ca71f62af516, i.e. the use of Procs when interpolation of the SQL is required.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 2605a54cb6..8d755b6848 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1087,7 +1087,8 @@ module ActiveRecord
#
# [:finder_sql]
# Specify a complete SQL statement to fetch the association. This is a good way to go for complex
- # associations that depend on multiple tables. Note: When this option is used, +find_in_collection+
+ # associations that depend on multiple tables. May be supplied as a string or a proc where interpolation is
+ # required. Note: When this option is used, +find_in_collection+
# is _not_ added.
# [:counter_sql]
# Specify a complete SQL statement to fetch the size of the association. If <tt>:finder_sql</tt> is
@@ -1162,11 +1163,14 @@ module ActiveRecord
# has_many :tags, :as => :taggable
# has_many :reports, :readonly => true
# has_many :subscribers, :through => :subscriptions, :source => :user
- # has_many :subscribers, :class_name => "Person", :finder_sql =>
- # 'SELECT DISTINCT people.* ' +
- # 'FROM people p, post_subscriptions ps ' +
- # 'WHERE ps.post_id = #{id} AND ps.person_id = p.id ' +
- # 'ORDER BY p.first_name'
+ # has_many :subscribers, :class_name => "Person", :finder_sql => Proc.new {
+ # %Q{
+ # SELECT DISTINCT people.*
+ # FROM people p, post_subscriptions ps
+ # WHERE ps.post_id = #{id} AND ps.person_id = p.id
+ # ORDER BY p.first_name
+ # }
+ # }
def has_many(name, options = {}, &extension)
Builder::HasMany.build(self, name, options, &extension)
end