Skip to content

Instantly share code, notes, and snippets.

@grayt0r
Last active February 9, 2016 12:39
Show Gist options
  • Save grayt0r/9a72c406f0cf6dcc0e02 to your computer and use it in GitHub Desktop.
Save grayt0r/9a72c406f0cf6dcc0e02 to your computer and use it in GitHub Desktop.
ds-references
import DS from 'ember-data';
export default DS.RESTAdapter.extend();
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string')
});
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
name: DS.attr('string'),
_barName: DS.attr('string'),
bar: DS.belongsTo('bar', { async: true }),
barId: Ember.computed(function() {
return this.belongsTo('bar').id();
})
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('bar', { path: '/bar/:barId' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
init() {
this._super(...arguments);
$.mockjax({
url: '/foos',
responseText: {
foos: [{
id: 1,
name: 'Foo 1',
_barName: 'Bar 2 (_)',
bar: 2
}]
}
});
$.mockjax({
url: '/bars/2',
responseText: {
bar: {
id: 2,
name: 'Bar 2'
}
}
});
},
model: function() {
return this.get('store').findAll('foo');
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend();
<b>Foos</b>
<ul>
{{#each model as |foo|}}
<li>
{{foo.name}}
{{link-to foo._barName 'bar' foo.bar.id}}
</li>
{{/each}}
</ul>
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {
"ds-references": true
}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "canary",
"ember-data": "canary",
"ember-template-compiler": "canary",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment