Hi.
I have been working with ember for about a year to mock up applications in a really fast and lovely way, after getting frustrated about how angular works. Of course all of this is done using ember-cli-mirage.
I am now to the point where I want to use ember to connect to real databases to deploy the apps instead of just mocking them. Those apps have been developed in php as that’s what I have mastered, in order to meet the deadline. However I cannot figure out how to model my data (or structure my queries) in order to be retrieved properly by ember, specially when it comes to relationships. I am working with a handmade PHP API and MySQL database.
For example, let’s say I have the following models:
models/house.js
export default DS.Model.extend({
street: DS.attr(),
number: DS.attr(),
neighbourhood: DS.belongsTo('neighbourhood'),
rooms: DS.hasMany('room')
})
models/room.js
export default DS.Model.extend({
name: DS.attr(),
width: DS.attr(),
height: DS.attr(),
house: DS.belongsTo('house')
})
Let’s say I have a route called house/
routes/house.js
export default Route.extend({
model () {
return this.get('store').findAll('house')
}
})
I expect this to return a list of houses with their rooms as a nested list on each house, as it does if done with mirage and factories. However this only returns the list of houses. The table “houses” does not have any reference to the rooms. Instead, the table rooms has a “houseId” on each room to link them.
If I populate my template with that model:
templates/house.hbs
{{#each model as |model|}}
<p>{{model.street}}</p>
<p>{{model.number}}</p>
<p>{{model.rooms}}</p>
{{/each}}
This is the output:
5th Ave.
#454
<DS.PromiseManyArray:ember583>
How should I handle this? Anything that points me to the right direction will be truly appreciated. I want to convince my team to develop our apps purely in ember and eventually to change our servers to node, but I have to make one step at a time and it will be to switch from php frontends to ember.
Thank you very much in advance.
Mike