Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

DataModel by picking Attributes from other defined DataModel

We famously call such DataModel as "Cherry Picked DataModel". Attributes are Cherry picked from some other defined model.

In this example SensorVendorInfo contains SensorVendorSysId, SensorVendorName defined and available in VendorInfo

Code Block
languagexml
titleUnique Constraint Violation Error
linenumberstrue
<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>
<DataModel name="SensorVendorInfo">
   <Attribute name="SensorVendorSysId" value="VendorInfo.VendorSysId"/>
   <Attribute name="SensorVendorName" value="VendorInfo.VendorName"/>
</DataModel>

Once VendorInfo Data is created using Create TQL Query. The SensorVendorInfo will automatically have the Data as well. 

Note that Data can be create in opposite direction as well i.e. Once created in SensorVendorInfo the common attributes will be available in VendorInfo as well.

Create VendorInfo Data:

Code Block
languagexml
titleUnique Constraint Violation Error
linenumberstrue
<Query>
  <Create>
    <VendorInfo>
      <vendorName>Phidget</vendorName>
      <vendorTitle>Sensor Provider</vendorTitle>
      <vendorAddress>
        <Street>123 TQL Way</Street>
        <City>Sunnyvale</City>
        <Zipcode>91234</Zipcode>
      </vendorAddress>
      <DeviceTypes>Sensors</DeviceTypes>
      <DeviceTypes>Actuators</DeviceTypes>
    </VendorInfo>
  </Create>
</Query>

Query SensorVendorInfo DataModel

Code Block
languagexml
titleFind on DataModel with Cherry picked Attributes
linenumberstrue
<Query>
  <Find>
    <SensorVendorInfo>
      <SensorVendorSysId ne=""/>
    </SensorVendorInfo>
  </Find>
</Query>

SensorVendorInfo Find Result Contains data created in VendorInfo DataModel.

Code Block
languagexml
titleFind Result of DataModel with Cherry picked Attributes
linenumberstrue
<Find Status="Success">
  <Result>
    <SensorVendorInfo>
      <SensorVendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</SensorVendorSysId>
      <SensorVendorName>Phidget</SensorVendorName>
    </SensorVendorInfo>
  </Result>
</Find>

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
languagexml
titleCherry picked DataModel
linenumberstrue
<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>
<DataModel name="SensorVendorInfo">
   <Attribute name="SensorVendorSysId" value="VendorInfo.VendorSysId"/>
   <Attribute name="SensorVendorName" value="VendorInfo.VendorName"/>
   <String Name="SensorTypes Cardinality="0..m"/>
</DataModel>

Let's create SensorVendorInfo now using Create TQL Query:

Code Block
languagexml
titleCreate DataModel from Cherry picked Attributes
linenumberstrue
<Query>
  <Create>
    <SensorVendorInfo>
      <SensorVendorName>Phidget</SensorVendorName>
      <SensorVendorTitle>Sensor Provider</SensorVendorTitle>
      <SensorTypes>Temperature</SensorTypes>
      <SensorTypes>Light</SensorTypes>
    </SensorVendorInfo>
  </Create>
</Query>

Let's do a Find on VendorInfo. We get the VendorInfo and VendorTitle data back.

Code Block
languagexml
titleFind VendorInfo
linenumberstrue
<Query>
  <Find>
    <VendorInfo>
      <vendorSysId ne=""/>
    </VendorInfo>
  </Find>
</Query>

Find VendorInfo Result

Code Block
languagexml
titleFind VendorInfo Result
linenumberstrue
<Find Status="Success">
  <Result>
    <VendorInfo>
      <VendorSysId>KNTR2FJXAAAAUAABA5OUP375</VendorSysId>
      <VendorName>Phidget</VendorName>
    </VendorInfo>
  </Result>
</Find>

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
languagexml
titleFind VendorInfo Result
linenumberstrue
<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"/>
</DataModel>