Side-loading objects with non-standard class names in EmberJS with Rails+active_model_serializers

前端 未结 3 1575
梦如初夏
梦如初夏 2021-02-09 08:21

I have a few models in Rails that look something like this:

class Issue < ActiveRecord::Base
  belongs_to :reporter, class_name: \'User\'
  belongs_to :assign         


        
3条回答
  •  粉色の甜心
    2021-02-09 08:54

    I had similar problem and have found solution at ActiveModel::Serializers readme. You can use :root option. Try something like this for issue serializer:

    class IssueSerializer < ActiveModel::Serializer
      attributes :id
      embed :ids, include: true
    
      has_one :reporter, :root => "users"
      has_one :assignee, :root => "users"
      has_many :comments
    end
    

提交回复
热议问题