Joins in SQL Computed Code specification?

Hi -

I have 3 classes: "Class A" has a property X, "Class B" has a property which is a Class A, and I have a "Class C" which has a property of a Class B.

Class A definition

Class USER.ClassA Extends %Persistent

{

Property Propx as %String;

}

Class B definition

Class USER.ClassB Extends %Persistent

{

Property Record as USER.ClassA;

}

Class C defintion (which is where I'm having my problem)

Class USER.ClassC Extends %Persistent

{

Property BRecord As USER.ClassB;

Property ARecord As USER.ClassA [ Calculated, SqlComputeCode = { ????? }, SqlComputed ];

Method ARecordGet() as USER.ClassA

{

 quit ..BRecord.ARecord

}

}

What I'm trying to figure out is, how can I define a property that is a calculated and SQL Computed property in Class C that would show the Class B's Class A value, but I can't find a syntax that works.

{ set {ARecord}={BRecord.ARecord} } doesn't work, nor does

{ set {ARecord}={BRecord->ARecord} }, nor does

{ set {ARecord}={BRecord}.{ARecord} }, nor does

{ set {ARecord}={BRecord}->{ARecord} } 

Before I put in an overt method call (with all of the overhead associated with that) I thought I would ask if there is some sort of curly-braced acceptable form that would work.

  • 0
  • 0
  • 209
  • 3
  • 2

Answers

Hi Chip,

 

{ Set {ARecord} = ##class(User.ClassB).RecordGetStored({BRecord}) } should work.

 

Just for the record: this is safe just because the Calculated keyword is also there. Without that it's potentially dangerous to refer anything outside of the current record in the SqlComputeCode. 

Attila, can you please elaborate on why it is potentially dangerous to refer to data outside of current record unless Calculated is specified?

I personally use Calculated only when property value might change during oref lifetime. If property value is not changed once object is in process memory, then there is no need for Calculated, as I understand -- Transient is enough.

You're absolutely right. My answer was not entirely precise: either Calculated or Transient is enough.

Out of curiosity, why would you need to have a calculated field for this setup? You can always access the properties on ClassC with the following query

SELECT BRecord->Record->Propx FROM SQLUser.ClassC

Using a instance.property coding is sometimes more appropriate for logic readability over expressing and executing a query.