Last active
August 4, 2016 08:53
-
-
Save grayt0r/3c466d2a085235f3a10588056c12a020 to your computer and use it in GitHub Desktop.
Save org and people
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
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
export default Model.extend({ | |
name: attr('string') | |
}); |
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
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
export default Model.extend({ | |
name: attr('string') | |
}); |
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
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: attr('string'), | |
bar: belongsTo('bar', { inverse: null }), | |
bazs: hasMany('baz') | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
$.mockjax({ | |
url: '/foos/1', | |
responseText: { | |
foo: { | |
id: '1', | |
name: 'I am foo', | |
bar: '2' | |
}, | |
bars: [{ | |
id: '2', | |
name: 'I am bar' | |
}] | |
} | |
}); | |
return this.get('store').findRecord('foo', 1); | |
}, | |
afterModel(model) { | |
let baz1 = this.get('store').createRecord('baz', { | |
name: 'I am baz 1' | |
}); | |
let baz2 = this.get('store').createRecord('baz', { | |
name: 'I am baz 2' | |
}); | |
model.get('bazs').pushObject(baz1); | |
model.get('bazs').pushObject(baz2); | |
console.log(model.toJSON({ includeId: true })); | |
console.log(model.serialize({ includeId: true })); | |
} | |
}); |
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
import RESTSerializer from 'ember-data/serializers/rest'; | |
import DS from 'ember-data'; | |
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin); |
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
import RESTSerializer from 'ember-data/serializers/rest'; | |
import DS from 'ember-data'; | |
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin); |
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
import RESTSerializer from 'ember-data/serializers/rest'; | |
import DS from 'ember-data'; | |
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, { | |
attrs: { | |
bar: { | |
serialize: 'records', | |
deserialize: 'id' | |
}, | |
bazs: { | |
serialize: 'records', | |
deserialize: false | |
} | |
} | |
}); |
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
{ | |
"version": "0.10.4", | |
"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.7.0", | |
"ember-data": "2.7.0", | |
"ember-template-compiler": "2.7.0", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment