1
if (isEmpty(contact) || isEmpty(get(contact, 'emails'))) {
  contact = yield store.findRecord('contact', contactId);
}

if (isEmpty(contact) || isEmpty(get(contact, 'emails'))) {
  flashMessages.danger(i18n.t('email.cpq_document_email_missing'));
  return false;
}

The second block runs when the promise is running and Im getting an error. Shouldn't it stop the flow until the promise is resolved.

The promise runs fine and it works the next time

Harsh Kumar
  • 334
  • 2
  • 12
  • 2
    Yes, assuming you're using ember-data `findRecord` should return a promise and wait. Please include all of the code in your component as well as the error you're seeing because the issue doesn't seem to be in this block. – jrjohnson Nov 07 '20 at 16:22

1 Answers1

2

Assuming you are using ember-data, you may be encountering a case where findRecord returns a cached record. This depends on if you've already loaded the record (perhaps from a previous findRecord, findAll or query on another route, and how the ember-data adapter is configured: shouldBackgroundReloadRecord and shouldBackgroundReloadAll are methods on the adapter that default to returning true. When those methods return true, the cached record is immediately returned, but the record(s) are fetched again in the "background".

Kate
  • 276
  • 1
  • 3
  • This makes sense, I already have the contact object, but it doesn't have emails properties so I'm fetching it again. Is there a way I can stop it from using the cached data? – Harsh Kumar Nov 10 '20 at 07:21
  • Adding { reload: true } fixed it, thanks for the clarification – Harsh Kumar Nov 10 '20 at 07:52