lib/goldiloader/association_info.rb in goldiloader-0.0.4 vs lib/goldiloader/association_info.rb in goldiloader-0.0.5
- old
+ new
@@ -1,12 +1,24 @@
+# encoding: UTF-8
+
module Goldiloader
class AssociationInfo
def initialize(association)
@association = association
end
+ def unscope?
+ Goldiloader::Compatibility.unscope_query_method_enabled? &&
+ @association.association_scope.unscope_values.present?
+ end
+
+ def finder_sql?
+ Goldiloader::Compatibility.association_finder_sql_enabled? &&
+ @association.options[:finder_sql].present?
+ end
+
if ActiveRecord::VERSION::MAJOR >= 4
def read_only?
@association.association_scope.readonly_value.present?
end
@@ -23,10 +35,27 @@
end
def group?
@association.association_scope.group_values.present?
end
+
+ def joins?
+ # Yuck - Through associations will always have a join for *each* 'through' table
+ (@association.association_scope.joins_values.size - num_through_joins) > 0
+ end
+
+ private
+
+ def num_through_joins
+ association = @association
+ count = 0
+ while association.is_a?(ActiveRecord::Associations::ThroughAssociation)
+ count += 1
+ association = association.owner.association(association.through_reflection.name)
+ end
+ count
+ end
else
def read_only?
@association.options[:readonly].present?
end
@@ -37,14 +66,19 @@
def limit?
@association.options[:limit].present?
end
def from?
- @association.options[:finder_sql].present?
+ false
end
def group?
@association.options[:group].present?
+ end
+
+ def joins?
+ # Rails 3 didn't support joins for associations
+ false
end
end
end
end