Last active
August 29, 2015 14:05
-
-
Save smithcommajoseph/9c7ef6ec987125f3d8e8 to your computer and use it in GitHub Desktop.
nonworking ember data example with relationships
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
| // lookup the store | |
| store = OC2.__container__.lookup('store:main'); | |
| // add a serializer to handle our embedded records | |
| // ...either I'm getting this wrong or this is a bug, | |
| // as I can't get this part to work | |
| OC2.ColorSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { | |
| attrs: { | |
| foos: {embedded: 'always'} | |
| } | |
| }); | |
| // Models | |
| OC2.Color = DS.Model.extend({ | |
| color: DS.attr(), | |
| foos: DS.hasMany('foo') | |
| }); | |
| OC2.Foo = DS.Model.extend({ | |
| name: DS.attr() | |
| }); | |
| // data | |
| t = { | |
| colors:[ | |
| { | |
| id: 1, | |
| color: "red", | |
| foos:[ | |
| { | |
| id:1, | |
| name:'something 1' | |
| }, | |
| { | |
| id:2, | |
| name:'something 2' | |
| } | |
| ] | |
| }, | |
| { | |
| id: 2, | |
| color: "green", | |
| foos:[ | |
| { | |
| id:3, | |
| name:'something 3' | |
| }, | |
| { | |
| id:4, | |
| name:'something 4' | |
| } | |
| ] | |
| }, | |
| { | |
| id: 3, | |
| color: "blue", | |
| foos:[ | |
| { | |
| id:5, | |
| name:'something 5' | |
| }, | |
| { | |
| id:6, | |
| name:'something 6' | |
| } | |
| ] | |
| } | |
| ] | |
| }; | |
| // push color data into the store | |
| store.pushMany('color', t.colors); | |
| // get a color | |
| color = store.getById('color', 1); | |
| // lookup foos | |
| // this will bomb with | |
| // TypeError: Cannot read property 'typeKey' of undefined | |
| color.get('foos'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment