Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4826

Fetch relations automatically

$
0
0

@ioanszabo wrote:

Hi,
I have two related models (Notification):

import DS from 'ember-data';
import MF from 'ember-data-model-fragments';

export default DS.Model.extend({
    type: DS.attr('string'),
    status: DS.attr('string'),
    details: DS.attr(),
    createdAt: DS.attr('date'),
    updatedAt: DS.attr('date'),
    ...
    document: DS.belongsTo('document')
});

Here is the Document model:

        import DS from 'ember-data';
        import MF from 'ember-data-model-fragments';

export default DS.Model.extend({
    type: DS.attr('string'),
    category: DS.attr('string'),
    number: DS.attr('string'),
    valid: MF.fragment('doc-valid'),
   ....
    details: MF.fragment('doc-details'),
	user: DS.belongsTo('user'),
    vehicle: DS.belongsTo("vehicle"),
});

What I want to do is when them model is fetching notification
I want to also fetch related documents by making additional requests for each of them.

I have tried { async: false }, but is not working.

E.g. this.store.findAll('notification) should result in notifications with documents. For each document a new request should be made automatically and then model should be ready only when all requests are ready.

Is possible?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles