Question
· Apr 10, 2021

Do we have one-to-one relationships in IRIS?

Hi All!

Examining the page here I see we have one-to-many and parent-child relationships supported in the InterSystems Objects model.

Do we support one-to-one too?

Discussion (5)1
Log in or sign up to continue

That is very neat. I have a situation at the moment where I want to force a single object in a class and I use %OnBeforeSave() to check that the field that I have used as a PK, IDKey, Unique has a specific value. Though this is not quite the same as a one:one relationship it is similar in the sence that I amtrying to do something that is not specifically addressed in the documentation or through a class attribute.

There is a bunch of auto-generated methods that might be useful:
https://community.intersystems.com/post/useful-auto-generated-methods

especially this one from @Eduard Lebedyuk 
#############################################################

But with PropertySetObjectId you can expedite things

set person = ##class(Person).%New()
set companyId = 123
do person.EmployedAtSetObjectId(companyId)

The main advantage is that company object doesn't have to be opened.

#############################################################