class ActiveModel::Serializer
def embedded_in_root_associations
def embedded_in_root_associations associations = self.class._associations included_associations = filter(associations.keys) associations.each_with_object({}) do |(name, association), hash| if included_associations.include? name if association.embed_in_root? association_serializer = build_serializer(association) hash.merge! association_serializer.embedded_in_root_associations serialized_data = association_serializer.serializable_object key = association.root_key if hash.has_key?(key) hash[key].concat(serialized_data).uniq! else hash[key] = serialized_data end end end end end