Problems adding record in a relation

Home for older / inactive topics

Problems adding record in a relation

Postby jasantana » Thu Jan 30, 2014 2:51 pm

Hi all

I have a problem addig a record in a related foundset. When running from mobile application I can see that the master record ID is the same as the foreign key in the children records (for example -1076) I can navigate thru all the forms in the application and I see those values are right but when I sync the master record gets a UUID and the children gets a different fk, equal between them but different to the parent key.

This is the data model declaration in the service application

Code: Select all
      /** @type {JSFoundSet<db:/galaco_mobile/orders>} */
      var _fsOrders = databaseManager.getFoundSet('db:/galaco_mobile/orders');
      _fsOrders.loadAllRecords();
      var _ordersRelations = new Array();
      _ordersRelations.push('orders_to_orders_details');
      dataModel.addFoundSet(_fsOrders, _ordersRelations);

      customers_to_customers$userid.loadAllRecords();
      var _customersRelations = new Array();
      _customersRelations.push('customers_to_customers_products');
      dataModel.addFoundSet(customers_to_customers$userid, _customersRelations);


and I create the record like this:

Code: Select all
   var _orderRC = foundset.getRecord(foundset.newRecord());
   _orderRC.customers_id = _customerID;
   _orderRC.fecha = new Date();
   databaseManager.saveData();
   if (_fromHistory) {
      // Get all the customers products and add them to the details table
      if (utils.hasRecords(_orderRC.orders_to_customers.customers_to_customers_products)) {
         _orderRC.orders_to_customers.customers_to_customers_products.loadAllRecords();
         /** @type {JSFoundset<db:/galaco_mobile/customers_products>}*/
         var _fsProducts = _orderRC.orders_to_customers.customers_to_customers_products;
         for (var i = 1; i <= _fsProducts.getSize(); i++) {
            _fsProducts.setSelectedIndex(i);
            if (utils.hasRecords(_fsProducts.getSelectedRecord().customers_products_to_products)) {
               /** @type {JSRecord<db:/galaco_mobile/orders_details>}*/
               var _rcItem = _orderRC.orders_to_orders_details.getRecord(_orderRC.orders_to_orders_details.newRecord());
               //_rcItem.orders_id = _orderRC.order_id;
               _rcItem.cantidad = 1;
               _rcItem.precio = _fsProducts.getSelectedRecord().customers_products_to_products.uc;
               _rcItem.importe = _rcItem.cantidad * _rcItem.precio;
               _rcItem.products_id = _fsProducts.getSelectedRecord().customers_products_to_products.product_id;
            }
         }
      }
   }


I'm sure I'm missing something but I do not get what it is. Any one can help me please?

Thanks in advance
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

UPDATE: Problems adding record in a relation

Postby jasantana » Thu Jan 30, 2014 5:21 pm

Doing some tests I have found out that creating the orders record, then sync, then creating the lines and then sync again everything works fine.

Seems to me that the lines don't get the real key from the orders table until it really exists on the back end.

Cheers,
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Problems adding record in a relation

Postby vschuurhof » Fri Jan 31, 2014 6:06 pm

The UUID's which are generated on the mobile clients will most probably be regenerated by the UUID generator. As a result, the foreign key relation is not valid anymore. I think you have 2 options to solve this issue:

1. Use the UUID that is generated in the mobile client solution and make sure the mobile service solution doesn't generate a new one.
2. Use the possibility to offer all the changes to the mobile service solution at once (see https://wiki.servoy.com/display/public/ ... e+solution). This allows you to receive all changed records in a single web service call and with this you could use a temporary "translation" object for new UUIDs which are created.

Are these options of any help?
Vincent Schuurhof
Servoy
vschuurhof
 
Posts: 69
Joined: Tue Dec 14, 2010 12:00 pm

Re: Problems adding record in a relation

Postby jasantana » Fri Jan 31, 2014 7:07 pm

Hi Vincent, thanks for your reply.

Option 1 is not valid for me because I guess you mean that the table should not have any sequence type. Then I would have problems when the application runs from Web or Smart Client.

I will give a try to option 2 unless I got wrong what you meant in option 1

Cheers,
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Problems adding record in a relation

Postby jasantana » Sun Feb 02, 2014 8:36 pm

Hi Vincent.

I have modified my data_BaseClass form to always use the UUI that comes from the mobile:

Code: Select all
/**
* Generic RESTful POST method to create a new data record
*
* @param {Object} pData
* @param {String} pVersion
* @param {UUID} pPK
* @param {{ws_authenticate:Array<Object>}} [pAuthenticator]
*
* @properties={typeid:24,uuid:"3D9A6A7A-84C4-44A7-99F6-0B522922EDA6"}
*/
function ws_create(pData, pVersion, pPK, pAuthenticator) {
   // Let's get the PK that comes from the mobile
   var pkName = databaseManager.getTable(foundset.getDataSource()).getRowIdentifierColumnNames()[0];
   var _mobilePK = pData[pkName];
   application.output('Mobile PK' + _mobilePK);

   var record = foundset.getRecord(foundset.newRecord());
   application.output('DB Auto PK' + record[pkName]);
   databaseManager.copyMatchingFields(pData, record, true);

   // Change the auto generated PK and use the one that came from the mobile
   record[pkName] = _mobilePK;

   application.output('Saved ' + foundset.getDataSource() + ' :' + databaseManager.saveData(record));
}


I Have not used the transaction option as I guess it is not needed using the mobile generated UUID.

Now it is saving the data properly, but the Sync gif in the web browser does not dissapear. Even all data is properly saved!!

Anything I could check?
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Problems adding record in a relation

Postby vschuurhof » Mon Feb 03, 2014 4:55 pm

Could you then please open the browser's console to see what exception is being thrown? I suspect that the synchronization process is not finalized properly.
Vincent Schuurhof
Servoy
vschuurhof
 
Posts: 69
Joined: Tue Dec 14, 2010 12:00 pm

Re: Problems adding record in a relation

Postby jasantana » Mon Feb 03, 2014 5:19 pm

This is the console in the browser:

Vincent0001.png
Vincent0001.png (148.33 KiB) Viewed 2903 times
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Problems adding record in a relation

Postby vschuurhof » Mon Feb 03, 2014 5:24 pm

Then I guess that you have found a bug which I have already found before. :roll:

I have created a case in JIRA (https://support.servoy.com/browse/SVY-5849) and it will be fixed in version 7.4.
Vincent Schuurhof
Servoy
vschuurhof
 
Posts: 69
Joined: Tue Dec 14, 2010 12:00 pm

Re: Problems adding record in a relation

Postby jasantana » Mon Feb 03, 2014 5:34 pm

Thanks Vincent.

I owe you one
Best regards,
Juan Antonio Santana Medina
[email protected]
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom


Return to Archive

Who is online

Users browsing this forum: No registered users and 1 guest