diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-16 21:15:34 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-16 21:15:34 -0200 |
commit | 88a296dccc401da143d90cad54b693ff06bf2b58 (patch) | |
tree | 48fffd9e694b6a9ffb5bed2b921e08edf1824f8c /activerecord/lib/active_record/associations | |
parent | 666a7e34f553cef4c8878362eafc79c7e3f310c3 (diff) | |
parent | b6a2baee830f464344b7cb82caaa528be1db7389 (diff) | |
download | rails-88a296dccc401da143d90cad54b693ff06bf2b58.tar.gz rails-88a296dccc401da143d90cad54b693ff06bf2b58.tar.bz2 rails-88a296dccc401da143d90cad54b693ff06bf2b58.zip |
Merge pull request #7983 from georgebrock/bug7950-squashed
Backport 4bc2ae0 to fix #7950
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/relation/calculations.rb
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index f9cffa40c8..226639ad37 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -33,6 +33,18 @@ module ActiveRecord private + def column_for(table_name, column_name) + columns = alias_tracker.connection.schema_cache.columns_hash[table_name] + columns[column_name] + end + + def bind(scope, column, value) + substitute = alias_tracker.connection.substitute_at( + column, scope.bind_values.length) + scope.bind_values += [[column, value]] + substitute + end + def add_constraints(scope) tables = construct_tables @@ -67,7 +79,9 @@ module ActiveRecord conditions = self.conditions[i] if reflection == chain.last - scope = scope.where(table[key].eq(owner[foreign_key])) + column = column_for(table.table_name, key.to_s) + bind_val = bind(scope, column, owner[foreign_key]) + scope = scope.where(table[key].eq(bind_val)) if reflection.type scope = scope.where(table[reflection.type].eq(owner.class.base_class.name)) |