fragment error
Hi,
can ember-data-copyable work with fragments? As soon as I make a fragment copyable the base model will not copy anymore Fragment.extend(Copyable.
Assertion Failed: You can only assign null, an object literal or a 'dossier/consumer' fragment instance to this property"
property is 'consumer'. and value is an 'instance' error comes from here : https://github.com/lytics/ember-data-model-fragments/blob/master/addon/attributes.js#L118
adding console.log(value) reveals two passing calls, and the last one fails, which looks different to me.
[Log] Class {__ember1513363568481: "ember1394", store: Class, _internalModel: InternalModel, currentState: Object, …} (vendor.js, line 128420)
[Log] Class {__ember1513363568481: "ember1395", store: Class, _internalModel: InternalModel, currentState: Object, …} (vendor.js, line 128420)
[Log] Class {__ember1513363568481: null, fn: function, args: [false], context: Class, owner: Class, …} (vendor.js, line 128420)
export default Model.extend(Copyable, Validations, {
dossierNumber: attr('string'),
openedDate: attr('date', { defaultValue: () => new Date() }),
owningCustomerId: attr('string'),
owningPracticeId: attr('string'),
consumer: fragment('dossier/consumer', { defaultValue: {} }),
});
export default Fragment.extend(Copyable, Validations, {
address: fragment('fragment/geography/address', { defaultValue: {} }),
birthday: attr('date'),
email: attr('string'),
name: fragment('fragment/person/name/personname', { defaultValue: {} }),
phone: attr('string'),
sex: attr('string'),
});
I think the only blocking issue that I know of are the transforms lookup (#5).
@mpirio might be of more help here.
Hello, and Happy New Year :)
ember-data-copyable works with fragments. Fragment extends Ember.Copyable (see fragment.js#L70) and ember-data-copyable use copy method (see mixins/copyable.jsL146).
You do not need to extends Copyable when you make a new Fragment :
export default Fragment.extend(Validations, {
address: fragment('fragment/geography/address', { defaultValue: {} }),
birthday: attr('date'),
email: attr('string'),
name: fragment('fragment/person/name/personname', { defaultValue: {} }),
phone: attr('string'),
sex: attr('string'),
});
If you need custom copy, redefine copy method like this :
export default Fragment.extend(Validations, {
address: fragment('fragment/geography/address', { defaultValue: {} }),
birthday: attr('date'),
email: attr('string'),
name: fragment('fragment/person/name/personname', { defaultValue: {} }),
phone: attr('string'),
sex: attr('string'),
copy(deep) {
// your custom copy
}
});
see https://emberjs.com/api/ember/2.18/classes/Ember.Copyable and https://github.com/lytics/ember-data-model-fragments/blob/master/addon/fragment.js#L91