-1

I'm facing a very critical issue where I can't persist my data to the server.

I am building a dashboard where the user can create new dashboards and customize existing ones. A dashboard layout will have one or more rows. Each row contains one or more cells which vary in width. Each cell will have one or more widget instances where it holds a reference to a particular widget. So you have data about widgets in another table. And I'm using table storage.

So I have the tables as follow.

Page, PageLayout, Row, Cell, CellWidgetInstance Widget, WidgetInstance

So I have models for all the above tables and added a store for getting a particular page layout.

Page HasMany PageLayout

PageLayout HasMany Row

Row HasMany Cell

Cell HasMany CellWidgetInstance

CellWidgetInstance HasOne WidgetInstance

WidgetInstance HasOne Widget

So I can build the entire view or the edit view modes of the page using the pageLayout returned from the store. So I can access to the Rows collection and go on to the lower levels.

Now the problem comes when I'm trying to save the changes. In the edit view user can add/remove rows, add/remove/update cells, add/remove WidgetInstances etc. And if the user wishes to click cancel after doing all these changes it should not go to the server and I should be able to reject all the changes in different levels. And if the user wishes to save I should be able to save all the changes in one transaction.

I hoped by adding all the necessary CUD (create/update/delete) proxies to the models, doing pageLayoutStore.sync() and pageLayoutStore.rejectChanges() would do the trick calling each model's create/update/delete urls as per the changes. But it seems although sencha supports retrieving the whole hierarchy it does not support saving as a hierarchy still.

So I'm now hitting a major blocker where I can implement the functionality I needed which is a very standard functionality in most cases. Saving/rejecting models and associated models.

I spent hours searching the web and the sencha forums and all they say is sencha still does not support saving associated data. And in one case there was a work around to save the models then and there without using the store. But in my case I can't do this as the user might cancel after editing.

Can anybody suggest a work around for this?

Many Thanks, Dushan

Dushan
  • 49
  • 1
  • 4

1 Answers1

0

You're absolutely right - Sencha does not support saving a nested document.

There are a few workarounds. The simplest one is to use the 'auto' type, at the top level, and give up the power of models the rest of the way down.

A slightly more complex version is to use a custom writer to your PageLayout class, so that it can construct the data to be sent by hand; this will give you full control, and allow you to save your models at the PageLayout level.

It's also possible to extend Model to allow for additional association types - I've done this for my current project, but it's somewhat complex (and, no, I'm not in a position to share it at this time). If you've only got one "top-level model" to save in this nested fashion, then the custom writer is the easiest.

Robert Watkins
  • 2,196
  • 15
  • 17