aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-10-09 02:46:57 +0000
committerRick Olson <technoweenie@gmail.com>2006-10-09 02:46:57 +0000
commit8e3bf70bcd496ae642fdae5ad7717ad8378de176 (patch)
tree61a47381adc2b388366bf1806ff3bedaeb570517 /activerecord/lib/active_record/associations.rb
parentccd32adecae3e95836effe8c96ac215e9b9e580e (diff)
downloadrails-8e3bf70bcd496ae642fdae5ad7717ad8378de176.tar.gz
rails-8e3bf70bcd496ae642fdae5ad7717ad8378de176.tar.bz2
rails-8e3bf70bcd496ae642fdae5ad7717ad8378de176.zip
Removes the ability for eager loaded conditions to be interpolated, since there is no model instance to use as a context for interpolation. #5553 [turnip@turnipspatch.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5264 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb32
1 files changed, 11 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 93f10c666c..459484f8c2 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -349,23 +349,17 @@ module ActiveRecord
# But that shouldn't fool you to think that you can pull out huge amounts of data with no performance penalty just because you've reduced
# the number of queries. The database still needs to send all the data to Active Record and it still needs to be processed. So it's no
# catch-all for performance problems, but it's a great way to cut down on the number of queries in a situation as the one described above.
+ #
+ # Since the eager loading pulls from multiple tables, you'll have to disambiguate any column references in both conditions and orders. So
+ # :order => "posts.id DESC" will work while :order => "id DESC" will not. Because eager loading generates the SELECT statement too, the
+ # :select option is ignored.
#
- # Please note that limited eager loading with has_many and has_and_belongs_to_many associations is not compatible with describing conditions
- # on these eager tables. This will work:
- #
- # Post.find(:all, :include => :comments, :conditions => "posts.title = 'magic forest'", :limit => 2)
- #
- # ...but this will not (and an ArgumentError will be raised):
- #
- # Post.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%'", :limit => 2)
- #
- # Also have in mind that since the eager loading is pulling from multiple tables, you'll have to disambiguate any column references
- # in both conditions and orders. So :order => "posts.id DESC" will work while :order => "id DESC" will not. This may require that
- # you alter the :order and :conditions on the association definitions themselves. Because eager loading generates the SELECT statement too,
- # the :select option is ignored.
- #
- # It's currently not possible to use eager loading on multiple associations from the same table. Eager loading will not pull
- # additional attributes on join tables, so "rich associations" with has_and_belongs_to_many is not a good fit for eager loading.
+ # You can use eager loading on multiple associations from the same table, but you cannot use those associations in orders and conditions
+ # as there is currently not any way to disambiguate them. Eager loading will not pull additional attributes on join tables, so "rich
+ # associations" with has_and_belongs_to_many are not a good fit for eager loading.
+ #
+ # When eager loaded, conditions are not interpolated. This is because the interpolation of lazy loaded conditions happens within the context
+ # of the object; when eager loading the object does not exist yet.
#
# == Table Aliasing
#
@@ -1567,7 +1561,7 @@ module ActiveRecord
aliased_table_name,
reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),
klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record?
- join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions]
+ join << "AND #{sanitize_sql(reflection.options[:conditions])} " if reflection.options[:conditions]
join
end
@@ -1583,10 +1577,6 @@ module ActiveRecord
def table_name_and_alias
table_alias_for table_name, @aliased_table_name
end
-
- def interpolate_sql(sql)
- instance_eval("%@#{sql.gsub('@', '\@')}@")
- end
end
end
end