lib/graphiti/resource/sideloading.rb in graphiti-1.0.alpha.25 vs lib/graphiti/resource/sideloading.rb in graphiti-1.0.alpha.26
- old
+ new
@@ -15,15 +15,19 @@
sideload = klass.new(name, opts)
if parent = opts[:parent]
parent.children[name] = sideload
else
config[:sideloads][name] = sideload
- apply_sideloads_to_serializer if rails_autoloading?
+ apply_sideload_to_serializer(name) if eagerly_apply_sideload?(sideload)
end
sideload
end
+ def apply_sideload_to_serializer(name)
+ Util::SerializerRelationships.new(self, config[:sideloads].slice(name)).apply
+ end
+
def apply_sideloads_to_serializer
Util::SerializerRelationships.new(self, config[:sideloads]).apply
end
def has_many(name, opts = {}, &blk)
@@ -103,11 +107,12 @@
end
memo
end
- def rails_autoloading?
- defined?(::Rails) && !::Rails.application.config.eager_load
+ def eagerly_apply_sideload?(sideload)
+ autoloading = defined?(::Rails) && !::Rails.application.config.eager_load
+ autoloading || sideload.resource_class_loaded?
end
end
end
end
end