Last active
October 7, 2016 18:49
-
-
Save ericop/1786dffcbf2b91ab7dd39f2f3f0b0f4b to your computer and use it in GitHub Desktop.
Embedded Records with _id
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Embedded Records with _id' | |
}); |
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
import DS from "ember-data"; | |
export default DS.Model.extend({ | |
title: DS.attr(), | |
author: DS.attr(), | |
chapters: DS.hasMany('chapter') | |
}); |
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
import DS from "ember-data"; | |
export default DS.Model.extend({ | |
name: DS.attr() | |
}); |
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
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('books', { | |
path: '/', resetNamespace: true | |
}, function () {}); | |
}); | |
export default Router; |
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
import Ember from 'ember'; | |
let storeBooks = { | |
data: [{ | |
id: 7, | |
type: 'book', | |
attributes: { | |
title: 'War and Peace', | |
author: 'Leo Tolstoy' | |
}, | |
relationships: { | |
chapters: {data: [{ | |
id: 12, | |
type: 'chapter', | |
}] } | |
} | |
},{ | |
id: 8, | |
type: 'book', | |
attributes: { | |
title: 'Ember-CLI 101', | |
author: 'Adolfo Builes' | |
}, | |
relationships: { | |
chapters: {data: [{ | |
id: 12, | |
type: 'chapter', | |
},{ | |
id: 13, | |
type: 'chapter', | |
}] } | |
} | |
}], | |
included: [ | |
{ | |
type: 'chapter', | |
_id: 12, | |
attributes: { | |
name: 'An Epic, Amazing Chapter' | |
} | |
}, | |
{ | |
type: 'chapter', | |
_id: 13, | |
attributes: { | |
name: 'Dont Repeat Yourself, DRY Code' | |
} | |
} | |
] | |
}; | |
export default Ember.Route.extend({ | |
model(){ | |
this.get('store').pushPayload(storeBooks); | |
//this.get('store').push(storeBooks); | |
//var storedBooks = this.store.findAll('book'); | |
var peekBooks = this.get('store').peekAll('book'); | |
//var queryBooks = this.store.query('book', {ids: [1, 2, 3] }); | |
var firstBook = this.get('store').peekAll('book', 1); | |
return peekBooks; | |
}, | |
actions: { | |
addBook() { | |
let newChapter = this.get('store').createRecord('chapter', { _id: 99, name: 'The Chapter of the Future'}) | |
let newBook = { | |
id: 9, | |
title: 'Some New Book', | |
author: 'You', | |
chapters: [newChapter] | |
}; | |
return this.get('store').createRecord('book', newBook); | |
} | |
} | |
}); |
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
import DS from 'ember-data'; | |
export default DS.JSONAPISerializer.extend({ | |
primaryKey: '_id' | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
background: #faf4f1; | |
font-size: 12pt; | |
} | |
.button-blue { | |
color: #FFF; | |
background-color: #33C3F0; | |
border-color: #33C3F0; | |
border-radius: 3px; | |
} | |
.button-blue:hover { | |
color: #FFF; | |
background-color: #1EAEDB; | |
border-color: #1EAEDB; | |
} | |
h1 { | |
font-family: 'Pacifico', cursive; | |
color: white; | |
text-shadow: 1px 1px 1px #000; | |
background: url('https://static.jsbin.com/custom/emberjs/navigation_background.png') repeat-x; | |
border-bottom: 1px solid #AA412F; | |
box-shadow: 1px 1px 1px #000; | |
background-size:cover; | |
border-radius: 4px; | |
} | |
li { | |
background-image: linear-gradient(-90deg, #f4d2c1, #e7624b); | |
border: 1px solid #faf4f1; | |
border-radius: 4px; | |
padding: 5px; | |
} |
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
{ | |
"version": "0.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.8.0", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "2.8.0", | |
"ember-testing": "2.8.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment