Module: ActiveRecord::FinderMethods

Defined in:
ext/active_record/finder_methods.rb

Defined Under Namespace

Classes: SunstoneJoinDependency

Instance Method Summary collapse

Instance Method Details

#apply_join_dependency(eager_loading: group_values.empty?) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'ext/active_record/finder_methods.rb', line 203

def apply_join_dependency(eager_loading: group_values.empty?)
  if connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
    join_dependency = SunstoneJoinDependency.new(base_class)
    relation = except(:includes, :eager_load, :preload)
    relation.arel.eager_load = Arel::Nodes::EagerLoad.new(eager_load_values)
  else
    join_dependency = construct_join_dependency(
      eager_load_values | includes_values, Arel::Nodes::OuterJoin
    )
    relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
  end

  if eager_loading && has_limit_or_offset? && !(
      using_limitable_reflections?(join_dependency.reflections) &&
      using_limitable_reflections?(
        construct_join_dependency(
          select_association_list(joins_values).concat(
            select_association_list(left_outer_joins_values)
          ), nil
        ).reflections
      )
    )
    if !connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
      relation = skip_query_cache_if_necessary do
        klass.connection.distinct_relation_for_primary_key(relation)
      end
    end
  end

  if block_given?
    yield relation, join_dependency
  else
    relation
  end
end