Last active
October 11, 2015 20:28
-
-
Save nehalist/8081e3f48e564ae5b8f6 to your computer and use it in GitHub Desktop.
This file contains 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
// Router | |
this.resource('notes', function() { | |
this.resource('notebook', { path: ':notebook_id' }, function() { | |
this.resource('note', { path: ':note_id' }); | |
}); | |
}); | |
// models/note.js | |
import DS from 'ember-data'; | |
var Note = DS.Model.extend({ | |
name: DS.attr('string'), | |
content: DS.attr('string'), | |
notebook: DS.belongsTo('notebook') | |
}); | |
Note.reopenClass({ | |
FIXTURES: [ | |
{ | |
id: 1, | |
name: 'First note', | |
content: 'hello', | |
notebook: 1 | |
}, | |
{ | |
id: 2, | |
name: 'Second note', | |
content: 'hello', | |
notebook: 2 | |
} | |
] | |
}); | |
export default Note; | |
// models/notebook.js | |
import DS from 'ember-data'; | |
var Notebook = DS.Model.extend({ | |
name: DS.attr('string'), | |
notes: DS.hasMany('note') | |
}); | |
Notebook.reopenClass({ | |
FIXTURES: [ | |
{ | |
id: 1, | |
name: 'First notebook' | |
}, | |
{ | |
id: 2, | |
name: 'Second notebook' | |
} | |
] | |
}); | |
export default Notebook; |
This file contains 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
// routes/notebook.js | |
// displays notes for a notebook | |
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model: function() { | |
return this.store.find('note'); | |
} | |
}); | |
// routes/notes.js | |
// overview of all notebooks | |
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model: function() { | |
return this.store.findAll('notebook'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment