active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

No serializer found for resource

Open rmcsharry opened this issue 3 years ago • 0 comments

I've scoured the closed issues and seen this occur many times, but it seems my case is unique.

What is especially weird is that my app still works for the subcategories despite the error in the log.

Expected behavior vs actual behavior

  1. Not to see [active_model_serializers] No serializer found for resource: #<Subcategory in my logs It appears 4 times always, twice each for the same two subcategories. (note the subcategories DO appear in the JSON response)

Steps to reproduce

Not sure I can reproduce it, but happy to give access to the repo.

These are the serializers:

class CategorySerializer < ActiveModel::Serializer
  attributes :id,
    :name
    
  has_many :subcategories
  has_many :category_attributes
end

class SubcategorySerializer < ActiveModel::Serializer
  attributes :id,
    :name

  belongs_to :category
end

class CategoryAttributeSerializer < ActiveModel::Serializer
  attributes :id,
    :name
    :value

  belongs_to :category
end

This is the controller action:

categories_controller.rb

  # GET /categories
  # GET /categories.json
  def index
    @categories = Category.all.includes(:subcategories, :category_attributes)
    render json: @categories, include: ['subcategories', 'category_attributes']
  end

Environment

ActiveModelSerializers Version (commit ref if not on tag): gem 'active_model_serializers', '~> 0.10.0'

Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-linux]

OS Type & Version: MacOS Catalina

Integrated application and version (e.g., Rails, Grape, etc): Rails 5.1.4

Backtrace

(e.g., provide any applicable backtraces from your application) n/a

Additonal helpful information

The JSON response includes the subcategories, even though the log reports No serializer found.

rmcsharry avatar Oct 25 '20 20:10 rmcsharry