Sometimes I need to find a subset of a related foundset. i.e. from form foo I load bar via foo_to_bar - fine so far. But then trying to do a reduce-search on form bar can be, er, interesting.
AFAICT, after executing bar.loadRecords(foo_to_bar) anything that "show()"s form bar repopulates bar’s foundset like bar.loadRecords(foo_to_bar). Whereas what I would like is to be able to (reliably) bar.loadRecords(foo_to_bar) then find(), set parameters, search(false, true) and get a subset of the original related foundset.
Another way of looking at this might be that I want to use the relation like a temporary filter paramter?
FWIW, Servoy 2.2rc3 (yes, I know, I should update).
You should just do a “find” - rather than “loadRecords()”. Sample:
//find the related records
controller.find
fk = globals.pk
controller.search()
//now search within the related set
//syntax: controller.search( [clearLastResults], [reduceSearch])
controller.find
myField = myValue
controller.search(false, true)
It helps insomuch as for the simple case (single parent) it clarifies that my workaround is just what you are suggesting.
But… in the general case of a set of parent records (being the current foundset thereof) I cant simply use “fk = globals.pk” - it needs to be more like “fk IN foundset.pk”. More specifically, the user has found a set of records in the parent table (let’s call it “foo”) and needs to navigate to the set of related child records (call the child table “bar”), via the relation foo_to_bar, and then further reduce the foundset of bar records. Suggestions?
Also, I have a bizzare situation which may be related to this. As above, the user navigates to a set of foo records. On this button I have two buttons:
(1) a per-record button which is to navigate from the current foo record to the related bar records. forms.barForm.controller.showRecords(foo_to_bar) works fine in the first instance.
(2) a per-form button which is to navigate from the current foundset of foo records to the set of related bar records. var convertedFoundSet = databaseManager.convertFoundSet(foundset, foo_to_bar); forms.barForm.controller.showRecords(convertedFoundSet); works here.
In the second case above, reduce-searching (in a method) appears to work OK. But in the first case the same scripted reduce-search returns the reduced set of records based on either:
(a) the last set of records found in case (2) above, or if there was no such set:
(b) the whole table of bar.
Aha ! If I script the first case like you suggested, it seems to work just fine. Which somewhat turns the question on it’s head: why does the second case work?
More importantly, can I rely on the second case continuing to work?
i don’t get it completely what you are doing
Because case (1) and (2) are really doing 2 different things.
The first one only shows the related records of the parent record you selected and the second one shows all related records of all the parent records in the parent foundset.
What case do you want?
Both. Seriously, the user needs the choice of selecting one parent or the foundset of parents and navigating to the corresponding set of child records.
My only remaining issue is being puzzled that the loadRecords(convertedFoundSet) case works as well as it does, and consequently wondering if I’m relying on behaviour that might change in some later upgrade.
convert foundset will always work as it does now
there is only a different sql generated. So if you do a reduce search there then youre search string is just appenden to that sql.
Was this the last thing that was open for this post?