Safely accessing foreign keys with slice mode

It is important to understand that a window mode entity instance has no slice date. It represents the car over a range of dates. With a reference to a window-mode entity instance, you can access simple properties such as a String or a number.

Generally speaking, with a window mode entity instance, do not access links to other entities by using standard foreign key properties on the object. For example, for a vehicle entity instance in window mode, do not access its PolicyLine property. In window mode, this property is unclear with respect to the policy line as-of date.

If you access foreign key fields on a window-mode entity instance, Gosu returns the value of that property as of the last second of the window mode object’s effective time. This is sometimes what you want, but in typical code it is not.

For example, suppose you have a window mode version of a car in a variable called vehicleUnsliced. The vehicleUnsliced.GarageLocation property returns the garage location as of one second before the expiration date of the vehicleUnsliced object.

Note: That date might not be the last moment before the expiration date of the car on the policy. It is only the last moment for this particular window mode object. There may be a version of this object with a later expiration date.

For typical code, do not rely on this feature to navigate to related objects since the return result is not typically what you want. Instead, it is typically best to convert the window mode entity instance to a slice mode entity instance and then access its related objects at that slice date.

Any objects that you access from it are now automatically in slice mode because you accessed them from a slice mode object.

Compare the following two code examples.

The following code slices a window mode vehicle and then gets its policy line at that date:

unslicedVehicle.getSlice(date).PolicyLine

The following code gets the PolicyLine property from an unsliced (window mode) version of a vehicle, and then slices that result. This result is potentially different from the previous example. That is because this relies on the window feature discussed earlier in the topic. Although it looks similar, this code may return a different result from the first example. This code gets the policy line as of the last moment of this car’s effective date range. Then, the code slices that policy line at the desired date.

unslicedVehicle.PolicyLine.getSlice(date)

The important thing to notice is that the two lines of code may access different policy lines entirely. The first one accesses the PolicyLine property as of an explicit date. The second one accesses the policy line as of an implicit date (one second before the expiration of that window mode entity instance).

Secondly, when you use the getSlice method, the date must be within the effective date range of that individual version of the object. With that in mind, notice that in the first example, the date must be within the effective date range of the unsliced car object. In the second example, the date must be within the effective date range of the policy line.

It is important to keep track of which entity instance is most appropriate to call getSlice on. If you do not know whether the current version is the correct one, get the version list and call its asOf method:

unslicedVehicle.VersionList.asOf(date).getSlice(date).PolicyLine
Important: Generally speaking, on a window mode object be careful with directly accessing any foreign key references or array references. If you access a foreign key or array property on a window mode entity instance, Gosu returns the value as of one second before the expiration date of that object. In typical code, this is not what you want. Instead, get the version list, then get the correct window mode version of the object, and then slice it at an explicit date. Carefully review the Gosu code examples in this topic.