2
이 문제에 대한 다른 해결책을 찾고 있었지만 Rails와 Ember 사이의 다형성 관계를 처리하는 최선의 방법을 찾지 못했습니다. 필자의 경우에는 "todos"라는 다형성 테이블이 있으며이 테이블과의 관계 중 하나가 "patient"입니다. 나는 할 일 기록을 얻지 만 그들은 그들이 관련된 어떤 환자인지 모른다. 이것에 대한 어떤 도움도 크게 감사 할 것입니다.Ember와 Rails의 다형성 관계
레일 모델 :
class TodoSerializer < ActiveModel::Serializer
attributes :id, :content, :todoable_id, :todoable_type
end
class PatientSerializer < ActiveModel::Serializer
attributes :id, :first_name, :last_name, :email
has_many :todos
embed :ids, include: true
end
엠버 데이터 모델 :
App.Todo = DS.Model.extend
todoable_id: DS.attr 'number'
todoable_type: DS.attr 'string'
content: DS.attr 'string'
patient: DS.belongsTo 'patient'
App.Patient = DS.Model.extend
firstName: DS.attr 'string'
lastName: DS.attr 'string'
email: DS.attr 'string'
todos: DS.hasMany 'todo', polymorphic: true, async: true
은 왜 모두'belongs_to을해야합니까? –
@SergioA. 좋은 캐치. 거기 있으면 안된다. 고맙습니다. – sturoid