getFoundSetUpdater(foundset) update all related child data

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

getFoundSetUpdater(foundset) update all related child data

Postby ernest.leon » Mon Feb 27, 2017 7:16 pm

Hi All,

Is there a way to have getFoundSetUpdater(foundset) update all related child data.
For example, we have our main list based on orders table. There is a relation orders_to_order_items. We provide users a popupMenu that provides order_items fields to be 'filled'. eg date item processed, date item sent

is there a way for us to get the foundset updater to update all of these related records?

Thanks
Ernest
ernest.leon
 
Posts: 2
Joined: Mon Feb 27, 2017 7:06 pm

Re: getFoundSetUpdater(foundset) update all related child da

Postby sean » Tue Feb 28, 2017 4:41 am

Hi Ernest,

Have a look at databaseManager.convertFoundSet

This will create a JSFoundSet whose underlying query will user the parent JSFoundSet's where clause and join the child records
It will perform well if you don't need to iterate, i.e. setting all records to the same column values. Then it is a single UPDATE sql statement generated

In your case, something like this:
Code: Select all
// get foundset for all items
var itemFS = databaseManager.convertFoundSet(orderFS, 'orders_to_order_items');

// get updater for items
var updater = databaseManager.getFoundSetUpdater(itemFS);

// update all matching records
updater.setColumn('date_item_processed', date1);
updater.setColumn('date_item_sent', date2);
var success = updater.performUpdate();
if(!success) {
    // custom message
}
Software Engineer
Servoy USA
sean
 
Posts: 370
Joined: Mon May 21, 2007 6:26 pm
Location: USA

Re: getFoundSetUpdater(foundset) update all related child da

Postby ernest.leon » Tue Feb 28, 2017 7:54 pm

Thanks Sean

I will give that a try

Ernest
ernest.leon
 
Posts: 2
Joined: Mon Feb 27, 2017 7:06 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 13 guests