lib/torque/postgresql/auxiliary_statement.rb in torque-postgresql-1.1.0 vs lib/torque/postgresql/auxiliary_statement.rb in torque-postgresql-1.1.1
- old
+ new
@@ -203,12 +203,19 @@
builder = association.klass.predicate_builder
foreign_table = ::Arel::Table.new(association.plural_name)
end
# Add the scopes defined by the reflection
+ # Possibilities:
+ # table
+ # table, foreign_klass
+ # table, foreign_table, foreign_klass
if association.respond_to?(:join_scope)
- args = [@query.arel_table]
- args << base if association.method(:join_scope).arity.eql?(2)
+ arity = association.method(:join_scope).arity
+ args = [@query.arel_table, foreign_table, base]
+ args.delete_at(1) if arity <= 2 # Delete foreign_table
+ args.delete_at(1) if arity <= 1 # Delete base (foreign_klass)
+
@query.merge(association.join_scope(*args))
end
# Add the join constraints
constraint = association.build_join_constraint(table, foreign_table)