foundset.loadRecords / controller.loadRecords -Did you know?

I filed a bug recently, and got some interesting response back from Johan with some detailed info I hadn’t seen before, so I thought it was worth sharing.

So,foundset.loadRecords(foundset) and controller.loadRecords(foundset) do completly different things “under the hood”. Even though their arguments are the same, and the documentation on the Wiki is also very similar for these functions, they are doing much different things.

foundset1.loadRecords(foundset2)
This takes the data in foundset2 and loads it into foundset1. They aren’t “shared”, they just happen to contain the same record sets (initially). Added records from foundset2 won’t effect foundset1 (or relating or unrelating from foundset2). In addition, if foundset2 were related, and foundset2.getRelationName() returned the relation, after loading into foundset1, foundset2.getRelationName() is null. However, you still “stuck” with the same related record set. foundset2.loadAllRecords() won’t get you back to a full foundset.

controller.loadRecords(foundset2)
This takes the foundset of the form, and sets it to the refernce of foundset2. So essentially foundset=foundset2. One will update the other, and if one is related doing a getRelationName() on both will return the same value.

PS. Here is a reference to the bug where you can see some of the actual comments: https://support.servoy.com/browse/SVY-3265

Hi Scott, thnkx for sharing!

@Servoy: let’s get some good documentation on the wiki, also including some good examples and comment on what each step is suppose to do…

Yes, thanks for sharing.
This is just the kind of thing which can cause a lot of trouble…

I vaguely remember there is a similar issue with loading records from a sorted dataset. You think you are loading the records in order, but your sort order is ignored…

Yep, we noticed that forms.myTableViewForm.foundset.loadRecords(_foundset_2) not always (?) takes over the _foundset_2.sort
The sort sign in the column header in that case is also not ok.

Servoy 5.2

Regards,

wauw :shock: Never knew that one!
There are tons of discussions here about when to use controller.loadRecords or foundset.loadRecords, but no one, point to this difference

Thanks Scott, for sharing

Thanks for sharing Scott! I’ve added your info in our Confluence docu :)

i have updated the doc, but that won’t be reflected right away in the wiki
it will be reflected in the code completion doc (when you code complete you get also a second popup with the doc).

I think it is quite logical, you are really calling it on 2 completely different objects…
But i will give an example, lets say we have 2 cups (coffee cup1, tea cup2 == 2 foundsets) and one dish (controller)

cup1 sits on the dish
then i now call controller (dish) loadRecords foundset2 (cup2)
what happens is that cup1 is removed from the dish and cup2 is placed on the dish (you are now drinking tea, but you still have that first coffee foundset somewhere that is not changed)

cup1 sits on the dish
then i now call foundset (cup1) loadRecors foundset2 (cup2)
what happens is that cup2 contents is poured into cup1 (cup1 is first emptied so the coffee is thrown away, and the tea is poured into it)
cup1 still sits on the dish but now has also tea instead of coffee (and cup2 still also has the same tea)

Thnkx Johan!