Question
Evgeny Shvarov · 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?

 

00
1 0 5 90
Log in or sign up to continue

Replies

YES ! but not it's addressed explicitly

  • the trivial one by self-restricting 1:many  to a single link
  • inheriting of classes is a 1:1 parent-child- relationship  (sample.person<-sample.employee)
  • the normal property -> object reference (sample.employee->sample.company)

Thanks, Robert!

So officially no, got you.

Inherited classes - a good one! Never thought about it like that.

Object property yes, but in fact could be a one-many.

an example of a self-referencing 1:1 relationship
it is also characterized by our "implicit join" feature  ->

Class Sample.Person Extends (%Persistent, %Populate)  {
 - - - 
 Property Spouse As Sample.Person
 Index sp On Spouse [ Unique ]; // to verify 1:1    
 - - -
 }

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.

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