Permalink
Browse files

Restore eager condition interpolation, document it's differences [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5284 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 214d236 commit 787049467341a75de469b58bcfe84f0959a2c3af @technoweenie technoweenie committed Oct 11, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* Restore eager condition interpolation, document it's differences [Rick]
+
* Don't rollback in teardown unless a transaction was started. Don't start a transaction in create_fixtures if a transaction is started. #6282 [Jacob Fugal, Jeremy Kemper]
* Add #delete support to has_many :through associations. Closes #6049 [Martin Landers]
@@ -358,8 +358,8 @@ def clear_association_cache #:nodoc:
# 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.
+ # When eager loaded, conditions are interpolated in the context of the model class, not the model instance. Conditions are lazily interpolated
+ # before the actual model exists.
#
# == Table Aliasing
#
@@ -1560,7 +1560,7 @@ def association_join
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 #{sanitize_sql(reflection.options[:conditions])} " if reflection.options[:conditions]
+ join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions]
join
end
@@ -1576,6 +1576,10 @@ def table_alias_for(table_name, table_alias)
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
@@ -351,6 +351,13 @@ def test_eager_load_has_many_through_has_many
assert_equal [1,2,3,5,6,7,8,9,10], author.comments.collect(&:id)
end
end
+
+ def test_eager_load_has_many_through_has_many_with_conditions
+ post = Post.find(:first, :include => :invalid_tags)
+ assert_no_queries do
+ post.invalid_tags
+ end
+ end
def test_eager_belongs_to_and_has_one_not_singularized
assert_nothing_raised do
@@ -315,7 +315,7 @@ def test_assignment_before_parent_saved
assert_equal a, firm.account
assert_equal a, firm.account(true)
end
-
+
def test_finding_with_interpolated_condition
firm = Firm.find(:first)
superior = firm.clients.create(:name => 'SuperiorCo')

0 comments on commit 7870494

Please sign in to comment.