View Full Version : Create dependent models

30 Jun 2012, 9:51 AM

I am trying to figure out how to create dependent models: Lets assume I have one model Book and one model Chapter, also two stores, two girds. Chapter has one field book_id to implement the association. The communication with the server is Ext Direct.

Everything works just fine, except if the Book and the Chapter are phantoms. IMHO the desired flow would be: sync the book store, update every Book with the server generated id, update every Chapter's book_id with the associated Book's id, sync the chapter store.

I cannot figure out any smart way of doing it. What is the Ext way of doing it?!

Thanks for your help!

2 Jul 2012, 1:59 AM
You can either first sync master (Book) and then sync slave (Chapter). If you want to avoid multiple requests you could combine both request to one (needs some coding) and let the server save first master then slave and return back the combined result. Then (again some coding), you can process the result to update both stores. I'm not aware of any easier built-in way.

Optionally, you can try Associations (http://docs.sencha.com/ext-js/4-1/#!/guide/data).

2 Jul 2012, 7:51 AM
Hey Saki,

Thanks for your help! I was going to first sync master, then sync slave. But: slave is associated to master via a master_id. Since the master is a phantom to begin with, the master's id will change during the sync, so master_id will contain an invalid value. I took a look at associations but I did not see how they address this problem. Any pointers on that?!

Thanks again, Dominik