Created
August 9, 2016 14:15
-
-
Save grayt0r/e185a7b9b641ed22757ef2775120f525 to your computer and use it in GitHub Desktop.
New Twiddle
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); | |
model.save({ | |
adapterOptions: { | |
embedOrg: 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 DS from 'ember-data'; | |
import RESTSerializer from 'ember-data/serializers/rest'; | |
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, { | |
attrs: { | |
//bar: { | |
// serialize: 'records', | |
// deserialize: 'id' | |
//}, | |
bazs: { | |
serialize: 'records', | |
deserialize: false | |
} | |
}, | |
serializeBelongsTo(snapshot, json, relationship) { | |
if (relationship.key === 'bar' && snapshot.adapterOptions && snapshot.adapterOptions.embedOrg === true) { | |
this._serializeEmbeddedBelongsTo(snapshot, json, relationship); | |
} else { | |
this._super(snapshot, json, relationship); | |
} | |
} | |
}); |
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