aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-03-12 09:32:20 +0000
committerJon Leighton <j@jonathanleighton.com>2011-03-12 09:32:20 +0000
commit37d93ea16046add35fecd8c279e868869ee744a5 (patch)
tree63b8ed837d69d2715dd0e46c9314967e1b2e73d0 /activerecord/lib/active_record/associations/join_dependency
parent17ea20426057aac43abcc0735534df31c577b918 (diff)
downloadrails-37d93ea16046add35fecd8c279e868869ee744a5.tar.gz
rails-37d93ea16046add35fecd8c279e868869ee744a5.tar.bz2
rails-37d93ea16046add35fecd8c279e868869ee744a5.zip
Fix tests under postgres - we should always put conditions in the WHERE part not in ON constraints because postgres requires that the table has been joined before the condition references it.
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 7dc6beeede..4121a5b378 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -74,7 +74,7 @@ module ActiveRecord
foreign_key = reflection.foreign_key
when :has_and_belongs_to_many
# Join the join table first...
- relation = relation.from(join(
+ relation.from(join(
table,
table[reflection.foreign_key].
eq(foreign_table[reflection.active_record_primary_key])
@@ -89,17 +89,20 @@ module ActiveRecord
foreign_key = reflection.active_record_primary_key
end
- conditions = self.conditions[i]
+ constraint = table[key].eq(foreign_table[foreign_key])
if reflection.klass.finder_needs_type_condition?
- conditions += [reflection.klass.send(:type_condition, table)]
+ constraint = table.create_and([
+ constraint,
+ reflection.klass.send(:type_condition, table)
+ ])
end
- relation = relation.from(join(
- table,
- table[key].eq(foreign_table[foreign_key]),
- *conditions
- ))
+ relation.from(join(table, constraint))
+
+ unless conditions[i].empty?
+ relation.where(sanitize(conditions[i], table))
+ end
# The current table in this iteration becomes the foreign table in the next
foreign_table = table