about summary refs log tree commit diff
path: root/config/initializers
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-03-28 13:01:33 +0100
committerThibaut Girka <thib@sitedethib.com>2019-03-28 13:01:33 +0100
commit050efbc12650feaac3e833c4dd740bf090e3dae1 (patch)
tree260458c7ff43dd82fc02cc7e5ef0920dd8d2a25b /config/initializers
parent0418bdd71f59b4d7e9f3498f2990c8b044f310e1 (diff)
parent24d5b6f9e39d2ac62a9657c7d19bc8c437b0735b (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/workers/activitypub/distribute_poll_update_worker.rb
- config/locales/pl.yml
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/active_model_serializers.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/config/initializers/active_model_serializers.rb b/config/initializers/active_model_serializers.rb
index 0e69e1d96..329a5fb2c 100644
--- a/config/initializers/active_model_serializers.rb
+++ b/config/initializers/active_model_serializers.rb
@@ -3,3 +3,22 @@ ActiveModelSerializers.config.tap do |config|
 end
 
 ActiveSupport::Notifications.unsubscribe(ActiveModelSerializers::Logging::RENDER_EVENT)
+
+class ActiveModel::Serializer::Reflection
+  # We monkey-patch this method so that when we include associations in a serializer,
+  # the nested serializers can send information about used contexts upwards back to
+  # the root. We do this via instance_options because the nesting can be dynamic.
+  def build_association(parent_serializer, parent_serializer_options, include_slice = {})
+    serializer = options[:serializer]
+
+    parent_serializer_options.merge!(named_contexts: serializer._named_contexts, context_extensions: serializer._context_extensions) if serializer.respond_to?(:_named_contexts)
+
+    association_options = {
+      parent_serializer: parent_serializer,
+      parent_serializer_options: parent_serializer_options,
+      include_slice: include_slice,
+    }
+
+    ActiveModel::Serializer::Association.new(self, association_options)
+  end
+end