Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

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.

Unique Constraint Violation Error
#
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:

Create Vendor Info
<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

Find on DataModel with Cherry picked Attributes
<Query>
  <Find>
    <SensorVendorInfo>
      <SensorVendorSysId ne=""/>
    </SensorVendorInfo>
  </Find>
</Query>

SensorVendorInfo Find Result Contains data created in VendorInfo DataModel.

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

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.

Create SensorVendor Info
<Create>
  <SensorVendorInfo>
        <SensorVendorName>Phidget2</SensorVendorName>   
  </SensorVendorInfo>
</Create>
<!-- Lets Find from VendorInfo -->
<Find>
  <VendorInfo>
     <VendorName ne=""/>
  </VendorInfo>
</Find>
<!-- Here is Find Result -->
<Find Status="Success">
  <Result>
    <VendorInfo>
      <VendorSysId>KP3XJHCLAAAAUAABBN4HSJE7</VendorSysId>
      <VendorName>Phidget2</VendorName>
    </VendorInfo>
  </Result>
  <Result>
    <VendorInfo>
      <VendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</VendorSysId>
      <DeviceTypes>Sensors</DeviceTypes>
      <DeviceTypes>Actuators</DeviceTypes>
      <VendorAddress>
        <City>Sunnyvale</City>
        <Street>123 TQL Way</Street>
        <Zipcode>91234</Zipcode>
      </VendorAddress>
      <VendorTitle>Sensor Provider</VendorTitle>
      <VendorName>Phidget</VendorName>
    </VendorInfo>
  </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.

Cherry picked DataModel
<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:

Create DataModel from Cherry picked Attributes
<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.

Find VendorInfo
<Query>
  <Find>
    <VendorInfo>
      <vendorSysId ne=""/>
    </VendorInfo>
  </Find>
</Query>

Find VendorInfo Result

Find VendorInfo Result
<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

Find VendorInfo Result
<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>
  • No labels