This is not a trick but a feature that I don't see used very often, but defining a unique index provides you with auto generated methods to get an oref to a row in a table by column value rather than by knowing the %ID of the row.
For example, here's a simple table with two columns:
class DC.Example Extends %Persistent {
Property Name As %String;
Property DOB As %Date;
Index NameIDX On Name [Unique];
}Let's insert a value into this table:
INSERT INTO DC.Example(Name, DOB) VALUES('John',TO_DATE('01 Jan 1986'))Suppose you know that one of the rows in a table contains the name "John" but you want to get their DOB, you can get the oref by using an auto-generated method called "NameIDXOpen()" like so:
set oref = ##class(DC.Example).NameIDXOpen("John")
write $ZDATE(oref.DOB) //prints out "01/01/86"For the curious: https://docs.intersystems.com/iris20261/csp/docbook/DocBook.UI.Page.cls…
- Log in to post comments