Has_many through association in active_model_serializer.

16 views
Skip to first unread message

Edsil Basadre

unread,
Sep 8, 2015, 8:44:36 PM9/8/15
to Ruby on Rails: Talk
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,
Reply all
Reply to author
Forward
0 new messages