5 Replies Latest reply on May 9, 2013 8:15 AM by Lars Burgess

    How to handle Models with composit keys?


      i have a table in the SQL server database which has a composite primary key defined, based on 2 column (uniqueidentifier + int), which is modeled with the same structure on the RhoElements application.

      when creating the records coming from the device, the record is created in the DB, however currently the updates are failing as the id received is device generated value like ("id"=>"136049073821905.94") which is not recognized by the DB.


      what should be returned back by the RhoConnect create function? how can i handle composite keys on devices so that the database integrity is maintained?



        • Re: How to handle Models with composit keys?

          Those are temporary ids created by the client, they don't need to be used when you create the record in the backend system.  If you see the update method example in the sample source adapter here: http://docs.rhomobile.com/rhoconnect/source-adapters#sample-adapter, the id attribute is removed from the hash before it is posted to the server.

            • Re: How to handle Models with composit keys?

              Hi Lars,

              as the back-end DB has not been modified, i am already removing the ID key from the create hash in the RhoConnect create function.

              my issues comes when the record is subsequently updated on the device. for instance if i have a model having the following properties:

              1. student_id
              2. module_id
              3. score


              as you said internally Rhom would create an id value to map to the three values. when a record 1st created on the device is received by RhoConnect the create hash would contain all three keys, together with the ID key in the hash. however, when the record is updated to change the value for score, the update hash only contains the score and ID keys, which makes it impossible for the back-end DB to identify which record has been updated.


              currently as a way round the issue, in the create function of RhoConnect i am returning a value by concatenating the student_id and module_id separated by a delimiter; and when the update hash is received the ID key contains this value which i am splitting to get the required composit key value. the tests so far have worked perfectly, but am not 100% sure on this.