Skip to content

Instantly share code, notes, and snippets.

@orlaqp
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlaqp/99b8bdc1b15e501bf33b to your computer and use it in GitHub Desktop.
Save orlaqp/99b8bdc1b15e501bf33b to your computer and use it in GitHub Desktop.
# 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'
@orlaqp
Copy link
Author

orlaqp commented May 2, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment