sort() removes newly created records from display

The sort() method in both controller and foundset removes newly created records from foundset/display. But when I log-out and log-in again, the sort method is working properly and displays all persisted records.

Here is the scenario:

  1. Create new record. Records are persisted in the database
  2. Check Grid. Grid displays additional record
  3. Execute sort method. Expected: Displayed records are sorted.
    Actual: Grid does not display newly created records. Sort removes records in foundset.

Workaround
4. Logout from the application.
5. Execute same sort method. Displayed records are sorted.

This problem is still occurring even when my relations are in LEFT OUTER JOIN already.

Is this the expected behavior of sort method?

This is not how sort ought to behave. What I expect is that you manipulated the the records that are part of the foundset by using filters and/or loading records. The newly created records aren’t part of the restrictions you applied through the filters or loadRecord() mechanism, so once you fire a sort, Servoy will requery the database based on the restrictions you applied and the newly created records disappear.

Paul

I’m having the same issue, Paul. Both creating a new record or duplicating an existing one.
A simple code like:

       var _theOffer = codpre
	var _theDb = db_name
	controller.newRecord(false)
	codpre = _theOffer
	db_name = _theDb
	section_zone = "*"
	section_sbzone1  = "*"
	section_sbzone2 = "*"
	controller.sort('idsez asc')

Shows the problem: the sort always removes the new record from the fset (for the reason you pointed out: I load a foundset in this form. Then I add a record to THIS foundset. If I don’t sort, the foundset is = originale fset + new record. If I sort, the new record is kicked out.
How can this be avoided? How can I make the sort act on the new fset? Should I re-load the foundset, that now includes the new record?


Tested on Servoy 4.1.5 and 4.1.7

If I’m not mistaken Johan commented on this problem some time ago in another thread.
I tried to find it, but couldn’t.

Maybe he’s willing to comment again, for current behaviour and eventually future behaviour.

i did?

Are you guys sure that the records are saved when you call sort? and when they are saved are they really part of the where criteria?

open your client, go to that method where you create an sort
First flush the admin pages performance log
then do you method

What do you see? Do you see an insert statement of that record and then the find query? And if you look at that would the new record really sit inside that foundset?

Just tested.
I move to list form and search a specific record (id 424).
Then I move to detail form using a loadRecord(foundset).
Call the method described above, where I added an applicationOutput and I get:
sql fset: select section_id from sections where section_id = ? order by codpre asc, section_zone asc, section_sbzone1 asc, from_sx_1 asc, from_dx_1 asc
params: [424]

Now my current foundset has 2 records (original 424 and the newly created one). If I call a sort, Servoy reloads the foundset with 424 only, excluding the new record, instead of sorting the new and the old record.
No matter if I save data or not.

I deal with the exact same situation.
I’m a 100% sure that records are saved, but without reloading the foundset on a form I can’t just sort my records.

ric,

That you loose the new record is completely logical…

You first search for a specific record so 424 so the foundset has a where id = 424

then you create a new record that doesnt have that id

then if you do a sort you get:

where id=424 sort A

then yes you loose the new record. because the new record doesnt comply with that where statement…

Mmm: I see what you mean, but I don’t agree completely on the “logical” part :)
See it from my perspective:
I have a fset of one record.
I create a new one.
The user sees 2 records.
I fire getSize and I get “2”.
Then I sort and the second record disappears.

How can I make the new record make part of the statement, in order to work with the sort method?

add that new record to the where criteria
so if you did do a find for the pk:
do another find for the pk and add then both of them.

Do remember sorting is done in the database. So it is a new query send to the database and the new results are shown to the user.
This can also happen if you just have a where X = Y and that shows 10 records

then another client alters one of these records so that X != Y (for that record)
if then this client does a sort it also would suddenly have 9 records…
Because the one doesn’t equal anymore.

Riccardino:
Mmm: I see what you mean, but I don’t agree completely on the “logical” part :)

+1