adopted-ember-addons / adopted-ember-addons/ember-data-model-fragments
Polymorphic not working?
- Linguagem predominante
- TypeScript
- Estrelas
- 367
- Forks
- 108
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Hi, I've been trying to get polymorphic records to work for the past day with no success.
I believe I have followed the instructions correctly and I have searched the open and closed issues but still no go. They work fine to an extent. However when instantiating the object it always gives me the parent object properties only.
I have a section which has an array of custom fields. Those custom fields are polymorphic
models/section.js
```
export default Fragment.extend({
name: attr('string'),
fields: fragmentArray('custom-field', { polymorphic: true, typeKey: 'fieldTypeName', defaultValue: []})
});
```
model/custom-field.js
```
export default Fragment.extend({
fieldTypeName: attr('string'), //this comes in as custom-field-textbox
description: attr('string'),
```
model/custom-field-textbox.js
```
import CustomField from './custom-field';
export default CustomField .extend({
maxCharacterLimit: attr('number'),
});
```
serializers/custom-field.js
```
serialize(record, options) {
let json = this._super(...arguments);
if (record instanceof BookingFormFieldTextbox) {
json.maxCharacterLimit = record.get('maxCharacterLimit');
}
return json;
}
});
```
// serializers/custom-field-textbox.js
```
import BookingFormFieldSerializer from './booking-form-field';
export default BookingFormFieldSerializer;
```
The API sends:
``` [{"
MaxCharacterLimit":50,
"FieldTypeName":"custom-field-textbox",
"Description":"textbox limit 60"}]
```
After the normalize function is called what I have is something like:
```
{data: {
attributes: {
fieldTypeName: "custom-field-textbox",
fieldType 6,
identity: 1,
description: '',
},
type: 'custom-field'
}
```
However then calling maxCharacterLimit returns null.
Should the type be `custom-field` or `custom-field-textbox` ?
Also when I use createFragment('custom-field-textbox'..) it works fine and I can see and use the property maxCharacterLimit. I then do a PUT to save it and the model in Ember still shows the property. However when I refresh so that it reloads the data from the server it instantiates the custom-field object but no properties of the custom-field-textbox are seen.
Any ideas why this is not working?
Thanks in advance.
Guia de contribuição
Direção de pesquisa
Start by tracing the normalize function and polymorphic type handling from models/section.js through model/custom-field.js and model/custom-field-textbox.js. Compare the serializers/custom-field.js and serializers/custom-field-textbox.js paths with createFragment('custom-field-textbox', ...) and the reload response. Done means refreshed API data instantiates the textbox subtype and exposes maxCharacterLimit consistently.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript
- Domínio
- frontend
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100