I have been looking up different solutions for this problem but I can't seem to find any sort of conclusion as how best to deal with polymorphic relationships between Rails and Ember. In my case I have a polymorphic table called "todos" and one of the relationships to that table is called "patient". I get the todo records but they don't know what patient they are associated with. Any help into this would be greatly appreciated.
RAILS MODELS:
class Todo < ActiveRecord::Base
belongs_to :todoable, polymorphic: true
end
class Patient < ActiveRecord::Base
has_many :todos, as: :todoable
end
RAILS SERIALIZERS:
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
EMBER DATA MODELS:
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 :todoable
andbelongs_to :patient
? - Sergio A.