Data Model
Relations

Entity Relationships Documentation

This document outlines the types of relationships between entities in a DataModel, focusing on how entities are interconnected. It emphasizes that the properties used to define these relationships are common across all relationship types, offering a unified approach to modeling entity relationships.

Common Relationship Properties

Regardless of the relationship type, the following properties are used to define the specifics of how entities relate to one another:

  • CascadeDelete: Indicates whether deleting an entity should automatically delete all related entities.
  • LogicalId: A unique identifier for the relationship.
  • Description: Provides a brief explanation of the relationship's purpose.
  • FirstEntityLogicalId: Identifies the first entity in the relationship.
  • SecondEntityLogicalId: Identifies the second entity in the relationship.
  • Properties: Details the property mappings between the entities involved in the relationship.

Relationship Types

OneToOneRelationship

Represents a relationship where one instance of an entity is related to one instance of another entity.

OneToManyRelationship

Describes a relationship where one instance of an entity is associated with multiple instances of another entity.

ManyToManyRelationship

Indicates a relationship where multiple instances of one entity are related to multiple instances of another entity.

Examples

OneToMany Relationship Example: Author and Post

{
  "RelationType": "OneToManyRelationship",
  "CascadeDelete": true,
  "LogicalId": "Author_Post",
  "Description": "An author can write many posts.",
  "FirstEntityLogicalId": "Author",
  "SecondEntityLogicalId": "Post",
  "Properties": [
    {
      "FirstEntityPropertyLogicalId": "Id",
      "SecondEntityPropertyLogicalId": "AuthorId"
    }
  ]
}

ManyToMany Relationship Example: Post and Tags

{
  "RelationType": "ManyToManyRelationship",
  "CascadeDelete": true,
  "LogicalId": "Post_Tags",
  "Description": "Posts can have multiple tags, and tags can be associated with multiple posts.",
  "FirstEntityLogicalId": "Post",
  "SecondEntityLogicalId": "Tag",
  "Properties": [
    {
      "FirstEntityPropertyLogicalId": "Tags",
      "SecondEntityPropertyLogicalId": "Id"
    }
  ]
}

Example with Entities

  "DataModel": {
    "Entities": [
      {
        "Properties": [
          {
            "DataType": "String",
            "MaxLength": null,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Id",
            "Description": null,
            "Required": false,
            "IsUnique": true,
            "AutoGenerate": true
          },
          {
            "DataType": "String",
            "MaxLength": 250,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Name",
            "Description": "Name",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          },
          {
            "DataType": "Enum",
            "EnumTyeLogicalId": "RoleType",
            "LogicalId": "Role",
            "Description": "Role ",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          },
          {
            "DataType": "Boolean",
            "DefaultValue": false,
            "LogicalId": "Active",
            "Description": "Active",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          }
        ],
        "LogicalId": "Author",
        "Description": "Author",
        "ExtensionsData": null
      },
      {
        "Properties": [
          {
            "DataType": "Int32",
            "MinValue": null,
            "MaxValue": null,
            "DefaultValue": null,
            "LogicalId": "Id",
            "Description": null,
            "Required": false,
            "IsUnique": true,
            "AutoGenerate": true
          },
          {
            "DataType": "String",
            "MaxLength": 250,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Name",
            "Description": "tag name",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          }
        ],
        "LogicalId": "Tag",
        "Description": "Tag",
        "ExtensionsData": null
      },
      {
        "Properties": [
          {
            "DataType": "String",
            "MaxLength": null,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Id",
            "Description": null,
            "Required": false,
            "IsUnique": true,
            "AutoGenerate": true
          },
          {
            "DataType": "String",
            "MaxLength": 250,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Title",
            "Description": "Title",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          },
          {
            "DataType": "String",
            "MaxLength": 5000,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "Content",
            "Description": "Content",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          },
          {
            "DataType": "String",
            "MaxLength": null,
            "DefaultValue": null,
            "RegularExpression": null,
            "LogicalId": "AuthorId",
            "Description": "AuthorId",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          },
          {
            "DataType": "PrimitiveArray",
            "ValueType": "String",
            "LogicalId": "Tags",
            "Description": "Tags",
            "Required": true,
            "IsUnique": false,
            "AutoGenerate": false
          }
        ],
        "LogicalId": "Post",
        "Description": "Post",
        "ExtensionsData": null
      }
    ],
    "Relationships": [
      {
        "RelationType": "OneToManyRelationship",
        "CascadeDelete": true,
        "LogicalId": "Author_Post",
        "Description": "content of the question template",
        "FirstEntityLogicalId": "Author",
        "SecondEntityLogicalId": "Post",
        "Properties": [
          {
            "FirstEntityPropertyLogicalId": "Id",
            "SecondEntityPropertyLogicalId": "AuthorId"
          }
        ],
        "ExtensionsData": null
      },
      {
        "RelationType": "ManyToManyRelationship",
        "CascadeDelete": true,
        "LogicalId": "Post_Tags",
        "Description": "post tags",
        "FirstEntityLogicalId": "Post",
        "SecondEntityLogicalId": "Tag",
        "Properties": [
          {
            "FirstEntityPropertyLogicalId": "Tags",
            "SecondEntityPropertyLogicalId": "Id"
          }
        ],
        "ExtensionsData": null
      }
    ],
    "LogicalId": "Blog",
    "Description": "Blog Example",
    "ExtensionsData": null
  }