<?xml version="1.0" encoding="iso-8859-1" ?>

<table>
  <base>CRM/Contact</base>
  <class>Relationship</class>
  <name>civicrm_relationship</name>
  <comment>Relationship between any 2 types of contacts.</comment>
  <add>1.1</add>
  <log>true</log>
  <icon>fa-handshake-o</icon>
  <paths>
    <view>civicrm/contact/view/rel?action=view&amp;reset=1&amp;cid=[contact_id_a]&amp;id=[id]</view>
    <delete>civicrm/contact/view/rel?action=delete&amp;reset=1&amp;cid=[contact_id_a]&amp;id=[id]</delete>
  </paths>

  <field>
    <name>id</name>
    <type>int unsigned</type>
    <title>Relationship ID</title>
    <required>true</required>
    <comment>Relationship ID</comment>
    <html>
      <type>Number</type>
    </html>
    <add>1.1</add>
  </field>
  <primaryKey>
    <name>id</name>
    <autoincrement>true</autoincrement>
  </primaryKey>
  <field>
    <name>contact_id_a</name>
    <type>int unsigned</type>
    <title>Contact A ID</title>
    <required>true</required>
    <comment>id of the first contact</comment>
    <html>
      <type>EntityRef</type>
      <label>Contact A</label>
    </html>
    <add>1.1</add>
  </field>
  <foreignKey>
    <name>contact_id_a</name>
    <table>civicrm_contact</table>
    <key>id</key>
    <add>1.1</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>
  <field>
    <name>contact_id_b</name>
    <type>int unsigned</type>
    <title>Contact B ID</title>
    <required>true</required>
    <comment>id of the second contact</comment>
    <add>1.1</add>
    <html>
      <type>EntityRef</type>
      <label>Contact B</label>
    </html>
  </field>
  <foreignKey>
    <name>contact_id_b</name>
    <table>civicrm_contact</table>
    <key>id</key>
    <add>1.1</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>
  <field>
    <name>relationship_type_id</name>
    <type>int unsigned</type>
    <title>Relationship Type ID</title>
    <required>true</required>
    <comment>Type of relationship</comment>
    <add>1.1</add>
    <html>
      <type>Select</type>
      <label>Relationship Type</label>
    </html>
    <pseudoconstant>
      <table>civicrm_relationship_type</table>
      <keyColumn>id</keyColumn>
      <nameColumn>name_a_b</nameColumn>
      <labelColumn>label_a_b</labelColumn>
    </pseudoconstant>
  </field>
  <foreignKey>
    <name>relationship_type_id</name>
    <table>civicrm_relationship_type</table>
    <key>id</key>
    <add>1.1</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>
  <field>
    <name>start_date</name>
    <uniqueName>relationship_start_date</uniqueName>
    <type>date</type>
    <title>Relationship Start Date</title>
    <comment>date when the relationship started</comment>
    <add>1.1</add>
    <html>
      <type>Select Date</type>
      <formatType>activityDate</formatType>
    </html>
  </field>
  <field>
    <name>end_date</name>
    <uniqueName>relationship_end_date</uniqueName>
    <type>date</type>
    <title>Relationship End Date</title>
    <comment>date when the relationship ended</comment>
    <add>1.1</add>
    <html>
      <type>Select Date</type>
      <formatType>activityDate</formatType>
    </html>
  </field>
  <field>
    <name>is_active</name>
    <type>boolean</type>
    <title>Relationship Is Active</title>
    <default>1</default>
    <required>true</required>
    <comment>is the relationship active ?</comment>
    <add>1.1</add>
    <html>
      <type>CheckBox</type>
      <label>Enabled</label>
    </html>
  </field>
  <field>
    <name>description</name>
    <type>varchar</type>
    <title>Relationship Description</title>
    <length>255</length>
    <comment>Optional verbose description for the relationship.</comment>
    <add>1.5</add>
    <html>
      <type>Text</type>
    </html>
  </field>
  <field>
    <name>is_permission_a_b</name>
    <type>int unsigned</type>
    <title>Contact A has Permission Over Contact B</title>
    <required>true</required>
    <default>0</default>
    <comment>Permission that Contact A has to view/update Contact B</comment>
    <add>2.1</add>
    <pseudoconstant>
      <callback>CRM_Core_SelectValues::getPermissionedRelationshipOptions</callback>
      <suffixes>name,label,icon</suffixes>
    </pseudoconstant>
    <html>
      <type>Radio</type>
    </html>
  </field>
  <field>
    <name>is_permission_b_a</name>
    <type>int unsigned</type>
    <title>Contact B has Permission Over Contact A</title>
    <required>true</required>
    <default>0</default>
    <comment>Permission that Contact B has to view/update Contact A</comment>
    <add>2.1</add>
    <pseudoconstant>
      <callback>CRM_Core_SelectValues::getPermissionedRelationshipOptions</callback>
      <suffixes>name,label,icon</suffixes>
    </pseudoconstant>
    <html>
      <type>Radio</type>
    </html>
  </field>
  <field>
    <name>case_id</name>
    <type>int unsigned</type>
    <component>CiviCase</component>
    <title>Case ID</title>
    <default>NULL</default>
    <comment>FK to civicrm_case</comment>
    <html>
      <type>EntityRef</type>
      <label>Case</label>
    </html>
    <add>2.2</add>
  </field>
  <field>
    <name>created_date</name>
    <type>timestamp</type>
    <comment>Relationship created date.</comment>
    <required>true</required>
    <default>CURRENT_TIMESTAMP</default>
    <add>5.47</add>
  </field>
  <field>
    <name>modified_date</name>
    <title>Relationship Modified Date</title>
    <type>timestamp</type>
    <required>true</required>
    <comment>Relationship last modified.</comment>
    <default>CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</default>
    <add>5.47</add>
    <readonly>true</readonly>
  </field>
  <foreignKey>
    <name>case_id</name>
    <table>civicrm_case</table>
    <key>id</key>
    <add>2.2</add>
    <onDelete>CASCADE</onDelete>
  </foreignKey>
</table>
