Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fragment error #15

Open
basz opened this issue Dec 15, 2017 · 2 comments
Open

fragment error #15

basz opened this issue Dec 15, 2017 · 2 comments

Comments

@basz
Copy link

basz commented Dec 15, 2017

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'),
});
@offirgolan
Copy link
Owner

I think the only blocking issue that I know of are the transforms lookup (#5).

@mpirio might be of more help here.

@mpirio
Copy link
Contributor

mpirio commented Jan 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants