Can I reference a type by a field other than its id?

#1

In a transform into Child, can I create a reference to Parent by referencing a field on Parent other than its id field, such as a secondary index? ie. is there a way of legitimizing the following snippets:

@db(index=['secondaryId'], unique=['secondaryId'])
entity type Parent schema name "PARENT" {
    secondaryId: string
    children: [Child](parent)
}

entity type Child schema name "CHILD" {
    parent: Parent
}

type TransformCanonicalChildToChild mixes Child transforms CanonicalChild {
    parent: ~ expression "{secondaryId: id_from_canonical}"
}
0 Likes

#2

Yes. We have a customer using this.

@db(unique=["meterTypeCompanyKey"])
remix type MeterAsset {

  //secondary key which will be used to link source systems with MeterAsset
  meterTypeCompanyKey:          string

}

remix type ServicePointMeterAsset {

// changing the reference from id to meterTypeCompanyKey for non-AMI meters

secondaryKey:                   string
meterTypeCompanyKeyAsset:       MeterAsset(meterTypeCompanyKey,secondaryKey)
amiAsset:                       MeterAsset(id,secondaryKey)
}
0 Likes