jeudi 29 août 2019

Why is ember changing the name of my model on the first save() attempt but not subsequent save() attempts?

I have a button that is linked to an action to update then save a model:

// component.js
resolveInvestigation(itemID) {
    let item = this.get('store').peekRecord('customers-investigations-item', itemID)

    set(item, 'status_id', 1)

    item.save()

}
// template.hbs

<button >

The button is part of a bootstrap 'card' style component so there are a few instances of it on the page.

If I click the button on card A I get a console error as follows:

Error: No model was found for 'customers-investigation-item'

I have no idea why it has decided to drop the s from 'investigations' - it doesn't even make the PATCH call. If I then click the button on Card B, the model saves correctly. If I reload the page and click Card B first, I get the error, then if I click Card A, it saves correctly.

I'm at a bit of a loss. I thought it might have been some weirdness with native class syntax or the @action decorator but I reverted to a classic component with no improvement. As an example, I am also saving this model in another part of the app with no issues as follows:

      let items = this.store.peekAll('customers-investigations-item').filter((item) => {
        if (item.isNew) {
          return true
        }
      })
      items.forEach(function (item) {
        if (item.isNew) {
          item.set('customer_id', response.id)
          item.save()
        }
      })

I first thought that it was some strrange plurilize/singularize behaviour occuring on save() but that wouldn't explain why subsequent saves after the initial attempt are fine, or how the model saves in other locations of the application.




Aucun commentaire:

Enregistrer un commentaire