Skip to content

Instantly share code, notes, and snippets.

@kkganesan
Created July 24, 2016 20:22
Show Gist options
  • Save kkganesan/f5d0c292f0e522a1e1b0cee673a39b65 to your computer and use it in GitHub Desktop.
Save kkganesan/f5d0c292f0e522a1e1b0cee673a39b65 to your computer and use it in GitHub Desktop.
Product With Books
import DS from 'ember-data';
export default DS.FixtureAdapter.extend();
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import DS from 'ember-data';
var Book = DS.Model.extend({
title: DS.attr('string'),
author: DS.belongsTo('author', { async: true })
});
Book.reopenClass({
FIXTURES: [
{
id: 1,
title: 'Learn Ember.js',
author: 1
},
{
id: 2,
title: '...',
author: 2
},
{
id: 3,
title: 'Profit!',
author: 2
}
]
});
export default Book;
import DS from 'ember-data';
var Product = DS.Model.extend({
name: DS.attr('string')
});
Product.reopenClass({
FIXTURES: [
{
id: 1,
name: 'shirt'
},
{
id: 2,
name: 'pants'
}
]
});
export default Product;
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('products', function() {
this.route('show', { path: ':id' }, function() {
this.route('books');
});
});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.store.find('product', params.id);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('product');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{link-to 'Products' 'products'}}
<br>
{{outlet}}
<br>
<br>
<ul>
{{#each model as |product|}}
<li>
{{link-to product.name 'product.show.books' product.id}}
</li>
{{/each}}
</ul>
{{outlet}}
{
"version": "0.10.1",
"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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment