Last active
August 29, 2015 14:00
-
-
Save orlaqp/99b8bdc1b15e501bf33b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for more details see: http://emberjs.com/guides/models/defining-models/ | |
class App.Commentable extends DS.Model | |
comments: DS.hasMany 'comment' | |
class App.Comment extends DS.Model | |
comments: DS.attr 'string' | |
commentable: DS.belongsTo 'commentable', polymorphic: true | |
class App.Client extends App.Commentable | |
firstName: DS.attr 'string' | |
lastName: DS.attr 'string' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RAILS MODELS
class Client < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: :true
end
RAILS SERIALIZERS
class ApplicationSerializer < ActiveModel::Serializer
embed :ids, :include => true
attributes :id
end
class ClientSerializer < ApplicationSerializer
attributes :first_name, :last_name
has_many :comments, :as => :commentable
end
class CommentSerializer < ApplicationSerializer
attributes :commentable_id, :commentable_type, :comments
has_one :commentable, polymorphic: :true
end