diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-27 10:57:40 -0800 |
---|---|---|
committer | George Brocklehurst <george.brocklehurst@gmail.com> | 2012-11-10 13:32:11 +0100 |
commit | a3cf03ef99b2cfd811e0ca5cd31ef57976a9408b (patch) | |
tree | 6dbf53fb64047463dcc4983f875f4242377a33eb /activerecord/lib/active_record/associations | |
parent | 5f508471b8919ec8d5fc3b6cbe24978a36de8150 (diff) | |
download | rails-a3cf03ef99b2cfd811e0ca5cd31ef57976a9408b.tar.gz rails-a3cf03ef99b2cfd811e0ca5cd31ef57976a9408b.tar.bz2 rails-a3cf03ef99b2cfd811e0ca5cd31ef57976a9408b.zip |
use bind values for join columns
This is a backport of 4bc2ae0da1dd812aee759f6d13ad428354cd0e13.
It fixes bug #7950.
Conflicts:
activerecord/lib/active_record/relation/calculations.rb
activerecord/lib/active_record/relation/finder_methods.rb
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 17 |
1 files changed, 16 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..0b689cfc08 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,10 @@ 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)) + #scope = scope.where(table[key].eq(owner[foreign_key])) if reflection.type scope = scope.where(table[reflection.type].eq(owner.class.base_class.name)) |