title: Accessing Parent object in Child serializer in ActiveModelSerializers
body: <p>Presenting a hypothetical, simplified version of my problem. Imagine I have a website where users can create a Shop with their own branding and choose from a catalog of Products to show in their Shop. Shops &amp; Products have a has-and-belongs-to-many (HABTM) relationship. Each Product has its own Shop-specific route.</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :shops do
      resources :products
    end
  end
  
  class ShopSerializer &lt; ActiveModel::Serializer
    has_many :products
  end
  
  class ProductSerializer &lt; ActiveModel::Serializer
    include Rails.application.routes.url_helpers
  
    attribute :url do
      shop_product_url(NEED SHOP ID, product_id: object.id)
    end  
  end
  </code></pre>
  
  <p>When a Shop is serialized, and as a result, so is the collection of its Products, I want the Product serializer to be aware of the shop that is serializing it and use that to include the route in the serialized output. How is this possible? I've tried all manner of passing <code>instance_options</code> from the <code>ShopSerializer</code> but it doesn't work as expected.</p>
  
  <pre><code># this works except is apparently not threadsafe as multiple
  # concurrent requests lead to the wrong shop_id being used
  # in some of the serialized data
  has_many :products do
    ActiveModelSerializers::SerializableResource.new(shop_id: object.id).serializable_hash
  end
  
  # shop_id isn't actually available in instance_options
  has_many :products do
    ProductSerializer.new(shop_id: object.id)
  end
  </code></pre>