I'm new to Ember and I'm trying to create an easy app where I have 2 models, Mountains and Ranges. A range has many mountains while a mountain belongs to a range. I want to create a relationship between them. I've searched through the web but I've found different explanations and I'm still struggling with this problem.
My models are:
mountain.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
altitude: DS.attr('number'),
range: DS.belongsTo('range', {async: true})
});
range.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
length: DS.attr('number'),
mountains: DS.hasMany('mountain', {async: true})
});
My mirage/scenario/default.js
file looks like this:
export default function(server)
{
var himalaya = server.create('range', {id: 1, name:'Himalaya', length:'16598' });
var karakorum = server.create('range', {id: 2, name:'Karakorum', length:'34801' });
var everest = server.create('mountain', {id:1, name: 'Everest', altitude: '8871', range_id:1 });
var K2 = server.create('mountain', {id:2, name: 'K2', altitude: '8657', range_id:2 });
}
and these are mirage/factories/range.js
and mirage/factories/mountain.js
files:
import Mirage, {faker} from 'ember-cli-mirage';
export default Mirage.Factory.extend({
});
Is this the right way to set up a relationship with mirage in Ember-CLI ? I'd also like to show in the himalaya page (I've already created a route and a template) all the mountains that belong to the range himalaya. How can I achieve this?
Thanks in advance.