We famously call such attributes as "CherryPicked Attributes". They are "Cherry Picked" from the attributes of some other defined models.
CherryPicked attributes are defined as type of Attribute. The value is defined as the name of an attribute from another model. For example, <Attribute name="SensorVendorSysId" value="VendorInfo.VendorSysId"/>.
In this example the DataModel SensorVendorInfo contains SensorVendorSysId, SensorVendorName defined and available from DataMdoel VendorInfo.
Code Block |
---|
language | xml |
---|
title | Unique Constraint Violation Error |
---|
linenumbers | true |
---|
|
#
DataModel(Name: "VendorInfo"):
Sid(Name: "VendorSysId")
String(Name: "VendorName")
String(Name: "VendorTitle")
PostalAddress(Name: "VendorAddress")
String(Name: "DeviceTypes", Cardinality: "0..m")
Unique(Name: "UniqueVendorName", Value: "VendorName")
DataModel(Name: "SensorVendorInfo"):
Attribute(Name: "SensorVendorSysId", value: "VendorInfo.VendorSysId")
Attribute(Name: "SensorVendorName", value: "VendorInfo.VendorName") |
Once VendorInfo Data is created using Create TQL Query. The SensorVendorInfo will automatically have the Data as well.
Create VendorInfo Data:
Code Block |
---|
language | xml |
---|
title | Create Vendor Info |
---|
linenumbers | true |
---|
|
#
Query:
Create:
VendorInfo:
vendorName: Phidget
vendorTitle: "Sensor Provider"
vendorAddress:
Street: "123 TQL Way"
City: Sunnyvale
Zipcode: 91234
DeviceTypes: Sensors
DeviceTypes: Actuators |
Query SensorVendorInfo DataModel
Code Block |
---|
language | xml |
---|
title | Find on DataModel with Cherry picked Attributes |
---|
linenumbers | true |
---|
|
#
Query:
Find:
SensorVendorInfo:
SensorVendorSysId(ne: "") |
SensorVendorInfo Find Result Contains data created in VendorInfo DataModel.
Code Block |
---|
language | xml |
---|
title | Find Result of DataModel with Cherry picked Attributes |
---|
linenumbers | true |
---|
|
#
Find(Status="Success"):
Result:
SensorVendorInfo:
SensorVendorSysId: chag3vw7tcet7dvg2athubjwl2gvth73
SensorVendorName: Phidget |
Note that Data can be created in opposite direction as well i.e. Once created in SensorVendorInfo the common attributes will be available in VendorInfo as well.
Code Block |
---|
language | xml |
---|
title | Create SensorVendor Info |
---|
linenumbers | true |
---|
|
#
Create:
SensorVendorInfo:
SensorVendorName: Phidget2
# Lets Find from VendorInfo
Find:
VendorInfo:
VendorName(ne: "")
#Here is Find Result
Find(Status: "Success"):
Result:
VendorInfo:
VendorSysId: KP3XJHCLAAAAUAABBN4HSJE7
VendorName: Phidget2
Result:
VendorInfo:
VendorSysId: chag3vw7tcet7dvg2athubjwl2gvth73
DeviceTypes: Sensors
DeviceTypes: Actuators
VendorAddress:
City: Sunnyvale:
Street: "123 TQL Way"
Zipcode: 91234
VendorTitle: "Sensor Provider"
VendorName: Phidget |
DataModel by picking Attributes from other defined DataModel + newly defined Attributes
DataModel can contain both cherry picked attributes as well as new attributes. Here SensorVendorInfo contains SensorTypes as new attribute of type string.
Code Block |
---|
language | xml |
---|
title | Cherry picked DataModel |
---|
linenumbers | true |
---|
|
#
DataModel(Name: "VendorInfo"):
Sid(Name: "VendorSysId"")
String(Name: "VendorName"")
String(Name: "VendorTitle"")
PostalAddress(Name: "VendorAddress"")
String(Name: "DeviceTypes", Cardinality: "0..m"")
Unique(Name: "UniqueVendorName", Value: "VendorName"")
DataModel(Name: "SensorVendorInfo"):
Attribute(Name: "SensorVendorSysId", value: "VendorInfo.VendorSysId"")
Attribute(Name: "SensorVendorName", value: "VendorInfo.VendorName"")
String(Name: "SensorTypes, Cardinality: "0..m"") |
Let's create SensorVendorInfo now using Create TQL Query:
Code Block |
---|
language | xml |
---|
title | Create DataModel from Cherry picked Attributes |
---|
linenumbers | true |
---|
|
#
Query:
Create:
SensorVendorInfo:
SensorVendorName: Phidget
SensorVendorTitle: "Sensor Provider"
SensorTypes: Temperature
SensorTypes: Light |
Let's do a Find on VendorInfo. We get the VendorInfo and VendorTitle data back.
Code Block |
---|
language | xml |
---|
title | Find VendorInfo |
---|
linenumbers | true |
---|
|
#
Query:
Find:
VendorInfo:
vendorSysId(ne: "") |
Find VendorInfo Result
Code Block |
---|
language | xml |
---|
title | Find VendorInfo Result |
---|
linenumbers | true |
---|
|
#
Find(Status: "Success"):
Result:
VendorInfo:
VendorSysId: KNTR2FJXAAAAUAABA5OUP375
VendorName: Phidget |
Selective Cherry picking using Constraint
In some cases we may want to selective pick attributes. For example, We only want Vendors with Sensor DeviceType. This can be achieved using Constraint.
In this case only Sensor DeviceTypes will be populated in SensorVendorInfo
Code Block |
---|
language | xml |
---|
title | Find VendorInfo Result |
---|
linenumbers | true |
---|
|
#
DataModel(name: "SensorVendorInfo"):
Attribute(name: "SensorVendorSysId", value: "VendorInfo.VendorSysId")
Attribute(name: "SensorVendorName", value: "VendorInfo.VendorName")
String(name: "SensorTypes", Cardinality: "0..m")
Constraint(target: "VendorInfo.DeviceTypes", eq: "lit.Sensor") |