Skip to main content

Object IDs

Object IDs

Each object has a unique ID within each extent to which it belongs. In most cases, you use this ID to work with the object. This ID is the argument to the following commonly used methods of the %PersistentOpens in a new tab class:

  • %DeleteId()

  • %ExistsId()

  • %OpenId()

The class has other methods that use the ID, as well.

How an ID Is Determined

InterSystems IRIS assigns the ID value when you first save an object. The assignment is permanent; you cannot change the ID for an object. Objects are not assigned new IDs when other objects are deleted or changed.

Any ID is unique within its extent.

The ID for an object is determined as follows:

  • For most classes, by default, IDs are integers that are assigned sequentially as objects of that class are saved.

  • For a class that is used as the child in a parent-child relationship, the ID is formed as follows:

    parentID||childID
    

    Where parentID is the ID of the parent object and childID is the ID that the child object would receive if it were not being used in a parent-child relationship. Example:

    104||3
    

    This ID is the third child that has been saved, and its parent has the ID 104 in its own extent.

  • If the class has an index of type IdKey and the index is on a specific property, then that property value is used as the ID.

    SKU-447
    

    Also, the property value cannot be changed.

  • If the class has an index of type IdKey and that index is on multiple properties, then those property values are concatenated to form the ID. For example:

    CATEGORY12||SUBCATEGORYA
    

    Also, these property values cannot be changed.

Accessing an ID

To access the ID value of an object, you use the %Id() instance method that the object inherits from %PersistentOpens in a new tab.

SAMPLES>set person=##class(Sample.Person).%OpenId(2)

SAMPLES>write person.%Id()
2
>>> person = iris.cls("Sample.Person")._OpenId(2)
>>> print(person._Id())
2

In SQL, the ID value of an object is available as a pseudo-field called %Id. Note that when you browse tables in the Management Portal, the %Id pseudo-field is displayed with the caption ID:

A display of the table Sample.Person, which includes a column marked with the caption ID.

Despite this caption, the name of the pseudo-field is %Id.

FeedbackOpens in a new tab