Has_many through association in active_model_serializer

Any thought how I can implement active_mode_serializer in a has_many
through association.

I have three models:

class Menu < ActiveRecord::Base

  • has_many :menu_details, inverse_of: :menu, dependent: :destroy*
  • has_many :foods, through: :menu_details*
    end

class Food < ActiveRecord::Base
has_many :menu_details
has_many :menu, through: :menu_details
ends

class MenuDetail < ActiveRecord::Base
belongs_to :menu
belongs_to :food
end

active model serializer

class MenuSerializer < ActiveModel::Serializer

  • attributes :id, :name, :price*
  • has_many :menu_details*
  • has_many :foods*
    end

class MenuDetailSerializer < ActiveModel::Serializer

  • attributes :id*

  • has_one :menu*

  • has_one :food*
    end

class FoodSerializer < ActiveModel::Serializer
attributes :id

has_many :menu_details
has_many :menu

end

I getting this error always:

Completed 500 Internal Server Error in 24ms

SystemStackError (stack level too
deep): app/controllers/menus_controller.rb:7:in `all’

Thanks*,*

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs