Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cyril-sf
Last active November 13, 2015 22:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyril-sf/515085e856f9dac2f06a to your computer and use it in GitHub Desktop.
Save cyril-sf/515085e856f9dac2f06a to your computer and use it in GitHub Desktop.
Polymorphic hasMany w/ FixtureAdapter
var User = DS.Model.extend({
messages: DS.hasMany('message', {polymorphic: true})
});
var Message = DS.Model.extend({
user: DS.belongsTo('user'),
body: DS.attr()
});
var Post = Message.extend({
comments: DS.hasMany('comment'),
title: DS.attr()
});
var Comment = Message.extend({
post: DS.belongsTo('post')
});
User.FIXTURES = [{
id: 1,
messages: [{
id: 1,
type: 'post'
}, {
id: 2,
type: 'comment'
}]
}]
Post.FIXTURES = [{
id: 1,
title: 'My first post',
body: 'This is interesting',
user: 1
}];
Comment.FIXTURES = [{
id: 2,
body: 'I forgot to add something'
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment