Playing around with ember data relationships.
This commit is contained in:
parent
0e16d2b0f4
commit
ecb376778c
8 changed files with 81 additions and 9 deletions
5
app/adapters/species.js
Normal file
5
app/adapters/species.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import DS from 'ember-data';
|
||||||
|
|
||||||
|
export default DS.RESTAdapter.reopen({
|
||||||
|
namespace: 'api'
|
||||||
|
});
|
|
@ -6,7 +6,8 @@ inflector.irregular('genus', 'genera');
|
||||||
|
|
||||||
export default DS.Model.extend({
|
export default DS.Model.extend({
|
||||||
genusName: DS.attr(),
|
genusName: DS.attr(),
|
||||||
createdAt: DS.attr(),
|
species: DS.hasMany('species', {async: true}),
|
||||||
updatedAt: DS.attr(),
|
createdAt: DS.attr('date'),
|
||||||
deletedAt: DS.attr()
|
updatedAt: DS.attr('date'),
|
||||||
|
deletedAt: DS.attr('date')
|
||||||
});
|
});
|
||||||
|
|
10
app/models/species.js
Normal file
10
app/models/species.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import DS from 'ember-data';
|
||||||
|
|
||||||
|
export default DS.Model.extend({
|
||||||
|
genusId: DS.attr(),
|
||||||
|
speciesName: DS.attr(),
|
||||||
|
genus: DS.belongsTo('genus', {async: true}),
|
||||||
|
createdAt: DS.attr('date'),
|
||||||
|
updatedAt: DS.attr('date'),
|
||||||
|
deletedAt: DS.attr('date')
|
||||||
|
});
|
|
@ -9,6 +9,7 @@ Router.map(function() {
|
||||||
this.route('login');
|
this.route('login');
|
||||||
this.route('about');
|
this.route('about');
|
||||||
this.resource('genera');
|
this.resource('genera');
|
||||||
|
this.resource('species');
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Router;
|
export default Router;
|
||||||
|
|
7
app/routes/species.js
Normal file
7
app/routes/species.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Route.extend({
|
||||||
|
model: function() {
|
||||||
|
return this.store.find('species');
|
||||||
|
}
|
||||||
|
});
|
|
@ -2,10 +2,13 @@
|
||||||
<div class="flakes-navigation">
|
<div class="flakes-navigation">
|
||||||
<ul>
|
<ul>
|
||||||
{{#link-to 'genera' tagName='li' href=false}}
|
{{#link-to 'genera' tagName='li' href=false}}
|
||||||
{{#link-to 'genera'}}Genera{{/link-to}}
|
{{#link-to 'genera'}}Genera{{/link-to}}
|
||||||
|
{{/link-to}}
|
||||||
|
{{#link-to 'species' tagName='li' href=false}}
|
||||||
|
{{#link-to 'species'}}Species{{/link-to}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
{{#link-to 'about' tagName='li' href=false}}
|
{{#link-to 'about' tagName='li' href=false}}
|
||||||
{{#link-to 'about'}}About{{/link-to}}
|
{{#link-to 'about'}}About{{/link-to}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
<h1>Genera</h1>
|
<p class="flakes-message information">This is here for debugging, this page will be deleted.</p>
|
||||||
|
|
||||||
<ul>
|
<div class="grid-1">
|
||||||
{{#each}}
|
{{#each}}
|
||||||
<li>{{genusName}}</li>
|
<div class="span-1">
|
||||||
|
<fieldset class="read-only-information">
|
||||||
|
<legend>{{genusName}}</legend>
|
||||||
|
<dl>
|
||||||
|
<dt>Created</dt>
|
||||||
|
<dd>{{createdAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Updated</dt>
|
||||||
|
<dd>{{updatedAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Deleted</dt>
|
||||||
|
<dd>{{deletedAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</div>
|
||||||
|
|
29
app/templates/species.hbs
Normal file
29
app/templates/species.hbs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<div class="grid-1">
|
||||||
|
{{#each}}
|
||||||
|
<div class="span-1">
|
||||||
|
<fieldset class="read-only-information">
|
||||||
|
<legend>{{speciesName}}</legend>
|
||||||
|
<dl>
|
||||||
|
<dt>Genus</dt>
|
||||||
|
<dd>{{genus.genusName}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Species</dt>
|
||||||
|
<dd>{{speciesName}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Created</dt>
|
||||||
|
<dd>{{createdAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Updated</dt>
|
||||||
|
<dd>{{updatedAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
<dl>
|
||||||
|
<dt>Deleted</dt>
|
||||||
|
<dd>{{deletedAt}}</dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
Reference in a new issue