diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-02 16:11:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-02 16:11:29 -0700 |
commit | 79b88e875b407f8418932fb757999909c2083b89 (patch) | |
tree | db0195ee27c7abfdce70b027d69e5aa875b19e97 /activerecord/lib | |
parent | 1a5394f4afdf2eeadd91b5b0ff5ad199c9dc93b0 (diff) | |
download | rails-79b88e875b407f8418932fb757999909c2083b89.tar.gz rails-79b88e875b407f8418932fb757999909c2083b89.tar.bz2 rails-79b88e875b407f8418932fb757999909c2083b89.zip |
fix to_sql output on eager loaded relations
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 18fdac2600..612f376c55 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -501,7 +501,15 @@ module ActiveRecord # User.where(name: 'Oscar').to_sql # # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar' def to_sql - @to_sql ||= klass.connection.to_sql(arel, bind_values.dup) + @to_sql ||= begin + if eager_loading? + join_dependency = construct_join_dependency + relation = construct_relation_for_association_find(join_dependency) + klass.connection.to_sql(relation.arel, relation.bind_values) + else + klass.connection.to_sql(arel, bind_values.dup) + end + end end # Returns a hash of where conditions. |