2017-05-25 28 views
0

我有一個participant模型,返回一個叫做participable的多態關係,我需要返回關係類型而不是類型participable。我在Ember前端使用。如何返回多態關係的類型?

class ParticipantSerializer < ApplicationSerializer # :nodoc: 
    attributes :id 

    belongs_to :dispute 
    belongs_to :participable, polymorphic: true 
end 
+1

'participant.participable_type' – Bartosz

+1

或'attributes:id,:participable_type' – Bartosz

回答

0

在我的情況的問題是不與多態關聯,與應用程序的邏輯。

我解決它通過participants創建另一個協會:

has_many :participants 
has_many :users, through: :participants, source: :participable, source_type: 'User' 
has_many :mediators, through: :participants, source: :participable, source_type: 'Mediator' 

我希望這幫助。