Search code examples
model-view-controllerextjsmodelassociationshas-one

Extjs sync hasOne model on store sync


I have two models: first one is PersonAddress, which contains info about person and address and second one is Address, which contains info about some address. I connect this to models with PersonAddress hasOne Address. Now I have store PersonAddresses, which contains few PersonAddress models. I want to create new one PersonAddress.

  1. I create Address
  2. I create PersonAddress
  3. I set Address for PersonAddress (personAddress.setAddress(address))
  4. Sync PersonAddresses store.

It tryes to create PersonAddress model on the server but my Address model is not created yet.

I want that store PersonAddress while syncing models automatically sync new Address model. Is it possible? It is important, because I use save button on form which contains parent model Person and I want only create Address and PersonAddress when I press save button on Person.

P.S.: Sorry for my English. And you can ask if you don't understand something.


Solution

  • Ok, I think the best way to do this is as I made:

    1. I add address field to PersonAddress model and made it persist.
    2. When I change address I set address field of PersonAddress and call setDirty() on it.
    3. On the server-side I get post data and extract address field.
    4. Make/Update my Address model on the server-side.
    5. Make/Update my PersonAddress model on the server-side.
    6. Connect Address with PersonAddress.