1 Reply Latest reply on May 21, 2013 2:09 AM by Kutir Mobility

    Creating/Combining nested model data in a single create method

      Not an entirely realistic case but for the sake of example, take simple Department->Product [1..n] models, instead of having a separate create method in the source adapters for each Department and Product, I need to send everything just on the Department's create.  The json would be similar to:

       

      { department: {

           id:temp1,

           deptname:electronics,

           products: [

                { id:temp1, name:prodname1 },

                { id:temp2, name:prodname2 }]

      }}

       

      In a nutshell, there would be separate query and update methods for both models, but the create is an all or nothing from the parent model only.

       

      So, questions are

      1) How to model this on the Rhodes side - do I need an additional NewDept class which would combine all the properties the Department and the Product - and then only have a create method for it?

      2) Or, can i reference the product's create_hash somehow from the Department's create method - and then update it's create_hash to pass everything?

       

      Also, in my case, the creation process in the backend may take quite a while ( and a lot of id's will be getting generated for various models ), so the create webservice will simply send back a 'Received' notice.

      1) How do I send that notice back to the device ( via Rhoconnect::Model::Exception.new("Submission Received!" ) ?

      2) How do I basically invalidate/remove the data from the device (or redis ) so it doesn't create again? My assumption here is that a future query will fetch the newly created department/products with generated id's, etc.

       

      Any advice, insight would be great!

       

      Thanks RT

        • Re: Creating/Combining nested model data in a single create method
          Kutir Mobility

          Hi Robert Toellner,

          1) How to model this on the Rhodes side - do I need an additional NewDept class which would combine all the properties the Department and the Product - and then only have a create method for it?

          Rhodes doesn't support nested model.

          I used nested model but just do the nested manually by doing look ups on IDs.

          2) Or, can i reference the product's create_hash somehow from the Department's create method - and then update it's create_hash to pass everything?

              It is not good way to sync with rhoconnect.

              ref: http://docs.rhomobile.com/rhodes/synchronization

          3) How do I send that notice back to the device ( via Rhoconnect::Model::Exception.new("Submission Received!" ) ?

            SyncEngine.set_notification uses to provide information about the sync process to a Rhodes application.

            To set a notification for a model, you can use the following method:

           

            SyncEngine.set_notification(

            Account.get_source_id,

            url_for(:action => :sync_notify),

            "sync_complete=true"

            )

           

            or

           

          Account.set_notification(

            url_for(:action => :sync_notify),

            "sync_complete=true"

            )

           

          4) How do I basically invalidate/remove the data from the device (or redis ) so it doesn't create again? My assumption here is that a future query will fetch the newly created department/products with generated id's, etc.

             When you sync with rhoconnect it calls create,update,delete and query method.It doesn't create a record which was created already again.

           

           

          Thanks

          Surendran S

          Kutir Mobility