Related foundsets: refresh after newRecord()

Hi…
I’m using a recommended technique from the handbook on adding new records in related foundsets which does something like this:

fsB = databaseManager.getFoundset(‘server_name’, ‘B’);
fsB.newRecord();
fsB.foreign_key = foundset.pk_id;
databaseManager.saveData();

Where fsB is a foundset of child records related to current foundset.

The code works fine but if I don’t save data at that point and try to perform any action that uses the relation fsA_to_fsB Servoy does not recognize the relation. Obviously, I need to refresh the relation somehow but nothing seems to work. Is there a way to sort this out? We set autoSave off and wouldn’t like to save at that point.

Thanks,
Maria

which handbook is that exactly?

what you seem to do is adding a new record of “orderlines” for a “order” right?
so B == “orderlines” and a == “order”

why are you doing that through a normal foundset that you get from the databasemanager
if you want to create related stuff, create it through the relation
so

var orderRecord = ordersFoundset.getRecord(x);
var orderLinesFs = orderRecord.order_to_orderlines;
orderLinesFs.newRecord();

and then you have your related new record and the foreign key is already filled in.

If you set those things your self in a normal (not related) foundset then yes related foundsets will only see it after you save.

jcompagner:
why are you doing that through a normal foundset that you get from the databasemanager
if you want to create related stuff, create it through the relation

The book says it’s more efficient to create records this way if the application is data intensive (which it is). Besides, it’s not always possible to go back in a many-to-many relation. It’s not that simple as creating a child record for a parent, I have this sort of relation: parent - linking table - another parent - child - another child - another linking table - yet another child. Being in the first linking table I need to create a record there which is related to both parents plus add all kids and stuff… And some tables do not have forms that represent the relation, so some tabs on some forms are unrelated, some have to be loaded with the help of sql statements, so things are more complicated than that.

The handbook version 1.5.2

to make a long story short, if you want to see records in a relation before you save, then you have to create them through the relation
If not then only on a save the relation will see that a new record is there for him and will add that one to its set.

Thanks for explanation Johan.
Here is another scenario, not involving new records but about refreshing related records.

What if I have a child form in a tab on a parent form. The tab displays the default child record for the parent, so it’s not parent_to_child but parent_to_child$default. From completely other form I manipulate one of these child records and take off the default flag from existing default child and put it on for another child record. autoSave is off all the time. Technically we already have another default child but the tab on the parent will display the old one until I save changes. Loading records in the tab does not work.
Is it the same short story? :)

yes same store, relatedfoundsets will only refresh there state on saveData()
It cant be earlier. because then at the moment you do walk through a rfs and you alter its key so it drops out it would be gone immediately
Thats not nice.