Created
August 24, 2012 06:06
-
-
Save jnx/3446339 to your computer and use it in GitHub Desktop.
Ember Associations
This file contains hidden or 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
App.Comment = DS.Model.extend( | |
body: DS.attr("string") | |
post: DS.belongsTo('App.Post') | |
validate: -> | |
if @get("body") is `undefined` or @get("body") is "" | |
"Comments require a body." | |
) |
This file contains hidden or 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
class CommentSerializer < ActiveModel::Serializer | |
attributes :body, :id, :post_id | |
end |
This file contains hidden or 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
App.Post = DS.Model.extend( | |
title: DS.attr("string") | |
body: DS.attr("string") | |
comments: DS.hasMany('App.Comment') | |
validate: -> | |
if @get("title") is `undefined` or @get("title") is "" or @get("body") is `undefined` or @get("body") is "" | |
"Posts require a title and body." | |
) |
This file contains hidden or 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
class PostSerializer < ActiveModel::Serializer | |
embed :ids, :include => true | |
attributes :title, :body, :id | |
has_many :comments | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment