diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/association_scope.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index b9bbeed4d5..ab102b2b8f 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -86,11 +86,14 @@ module ActiveRecord scope = scope.where(interpolate(condition)) end else - scope = scope.joins(join( - foreign_table, - table[key].eq(foreign_table[foreign_key]), - *conditions[i] - )) + constraint = table[key].eq(foreign_table[foreign_key]) + join = join(foreign_table, constraint) + + scope = scope.joins(join) + + unless conditions[i].empty? + scope = scope.where(sanitize(conditions[i], table)) + end end end |