So I have an ActiveRecord class with a couple different named scopes that include join parameters. While running a report, I happen to have a situation where one gets called inside of the other:
1 Model.scope_with_some_joins.find_in_batches do |models|
2 models.each do |mdl|
3 other_comparisons = Model.scope_with_other_joins
4 end
5 end
My problem is on line 3 -- I get a runtime error showing me that for some reason when running the second query it's maintaining the join scope from the outer query. Really I need it to be run separately on it's own, without sharing context with the outer query. Any thoughts or ideas?
(I should mention that the problem is an "ambigious column" error because there is one table that is joined in from both queries)