Ruby on Rails
Tuesday, September 8, 2015
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'
SystemStackError (stack level too deep):
app/controllers/menus_controller.rb:7:in `all'
Thanks,
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/40ecadbd-59b2-400b-85fd-9af8d514c1a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment