adopted-ember-addons / adopted-ember-addons/ember-data-model-fragments

Error while validating with ember-model-validator

Abierto
#478 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
367
Forks
108
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello, I have a model with a fragment from `ember-data-model-fragments`
And I use `ember-model-validator`
Before saving I run `validate` to validate fields.

When I have an error in a field (ex, name) , it throws this uncaught error on the adapter instead of adding the field error (ex "Name is empty") to the model with the fragment even though the error that the validation caught was not the fragment property.

` Error: Attempted to handle event `becameError` on while in state root.loaded.saved.`

the stack trace is this

[commitWasRejected](https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/11e263b11c911a23c430db8bd2b77a1f40eef68c/addon/record-data.js#L848)

[commitWasRejected](https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/11e263b11c911a23c430db8bd2b77a1f40eef68c/addon/record-data.js#L124)

[_fragmentCommitWasRejected](https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/11e263b11c911a23c430db8bd2b77a1f40eef68c/addon/record-data.js#L1008)

In the first [commitWasRejected](https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/11e263b11c911a23c430db8bd2b77a1f40eef68c/addon/record-data.js#L848), updating it from
```
const fragment =
key in this._inFlightFragments
? this._inFlightFragments[key]
: this._fragmentData[key];
if (fragment == null) {
continue;
}
behavior.commitWasRejected(fragment)
```
to

```
const fragment = this._inFlightFragments[key]
if (fragment == null) {
continue;
}
behavior.commitWasRejected(fragment)
```

to remove the tenary operator to strictly use `this._inFlightFragments[key]` seems to solve the issue but I am not sure if this is safe to do. All I was doing was to revert to this [5.0 version](https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/7ea57179eff9063530ac4fd42097604540887f25/addon/record-data.js#L479)

versions
```
"ember": 4,4,1,
"ember-data": "~4.4.0",
"ember-model-validator": "3.14.0",
"ember-data-model-fragments": "^6.0.3",
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.