I have two models, users and activities. Each user can have many activities, and each activity has one user. My models look like this:
App.Activity = DS.Model.extend(
user: DS.belongsTo('user', async: true)
and
App.User = DS.Model.extend
activities: DS.hasMany('activity', async: true)
I display the activities using
article#lead
h1= model.name
each activity in model.activities
p
= activity.id
p
= activity.user.name
I get a list of the activities, with a user name for each, but each user is triggering a separate request to the api - very slow and expensive. I want to know if I cant request the users in a single query.
My reading suggested I could simply set 'coalesceFindRequests' to true, but this didn't work for me
DS.RESTAdapter.reopen
namespace: 'api/v1'
coalesceFindRequests: true
App.Store = DS.Store.extend(
serializer: DS.RESTSerializer.extend
primaryKey: (type) ->
'_id';
)
App.ApplicationAdapter = DS.ActiveModelAdapter.extend()
Any pointers on what I'm doing wrong?. I'm very new to ember.
Thanks :)
Aucun commentaire:
Enregistrer un commentaire