Last active
November 13, 2015 22:29
-
-
Save cyril-sf/515085e856f9dac2f06a to your computer and use it in GitHub Desktop.
Polymorphic hasMany w/ FixtureAdapter
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
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