mardi 22 août 2017

Cannot call set with

I am trying my hands on ember js and I am not able to use multiple models within models,

model/client.js
export default DS.Model.extend({
  person: DS.belongsTo('person', {async: false, inverse: 'client'}),
  postalAddress : DS.belongsTo('address', {async: false}) ,
  residentialAddress : DS.belongsTo('address', {async: true})  ,
  personName: DS.attr('string'), //added from person
  greeting : DS.attr('string') //added from person
  });
model/person.js
export default DS.Model.extend({
  name : DS.attr('string'),
  personName : DS.attr('string'),
  greeting : DS.attr('string')  ,
  client: DS.belongsTo('client', {inverse: 'person'})
});

My Route routes/client/create

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return Ember.RSVP.hash({

        'client': this.get('store').createRecord('client'  ,
          { //does this not initialize person
            person: 'person', address: 'address'
          } ),
        // )
//does this not initialize person
          'person': this.get('store').createRecord('person',{
            client: 'client'
          }),
          'address': this.get('store').createRecord('address')
      }
    );
  }
});

my template has only one line :



in my client-form.hbs i had some fields that referred to client.person.personName or client.person.greeting, and when i would type the first character I would get for greeting or personName

Assertion Failed: Cannot call set with 'greeting' on an undefined object.

So I added personName and greeting in client model directly as well and added two fields referring to client.personName and client.greeting and those fields dont give me any issue. I believe that the person model is not initialized and perhaps the client is instantiated but person and address is not and person is an undefined object.

The reason for such a model is that I have a java backend and my ClientDTO looks like:

public class ClientDTO /*implements IsSerializable*/ {

    private PersonDTO personDTO;
    private AddressDTO postalAddress;
    private AddressDTO residentialAddress;

Where have i missed initializing the person and address, I can find ppl having errors "cannot call get on undefined" but not in set.




Aucun commentaire:

Enregistrer un commentaire