Slevin
Slevin

Reputation: 4222

No template update after createRecord with findQuery fetching

I'm wonder why my template doesn't get updated after createRecord when using findQuery to fetch data.

When changing this return this.store.findQuery('timetracking', {year: year, month: month, user_id: user_id}); to return this.store.find('timetracking'); the template gets updated with my new records.

I don't want to fetch all records to save bandwith, but when using only find/findQuery with query params, my newly created records doesn't show up in my template.

Do I have to do a "force" reload? And how to do this?

Update

The Ember inspector shows the new records.

Upvotes: 3

Views: 931

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

findQuery puts the job of filtering on the server's back. Ember Data assumes that the results that were returned are the only results that are associated with that collection. find with no query or id (findAll) will always return all records found in the store, because it realizes you weren't looking for any filtered set, if you create a new record it gladly knows to include it in all of the available records. You can manually push a record into a collection of records using pushObject.

// assuming you're in the context of your `findQuery` results, and they are the model
var model = this.get('model'),
    record = this.store.createRecord('timetracking', {...});

model.pushObject(record);

Upvotes: 5

Related Questions