Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Does a 1:n relationship keep the order of insertion?

Question
Martin Staudigel · May 12, 2021

Does a 1:n relationship keep the order of insertion?

Hello Community,

we read data from an Oracle database. The desired order is created by an 'order by' in the sql statement. The individual elements of the result set are converted into objects and inserted into a parent object using 'insert' on a property, which implements a one-to-many relationship with the result objects. Later, we iterate over the objects in a for loop and process the contents. At this point the order is apparently no longer identical to the order in which the elements were inserted.

The fundamental question at this point: Is the described relationship aware of the concept of sequence and also reliably assures it? An implementation in use relies on this, but recently the order of the results in the cache object is no longer identical to the sorting of the SQL select. Is it possible that this has only worked by luck over the years?

Regards and thanks for your support,

Martin Staudigel

#Caché
Product version: Caché 2018.1
$ZV: Cache for UNIX (SUSE Linux Enterprise Server for x86-64) 2018.1.3 (Build 414_0_19402U) Mon Nov 18 2019 22:54:54 EST [HealthShare Modules:Core:15.032.9026 + Linkage Engine:15.032.9026]

Source URL:https://community.intersystems.com/post/does-1n-relationship-keep-order-insertion