Body: <p>Since this morning I'm running into something strange when using the API to update a relationship.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>CRM.api3('Relationship', 'create', {
      "sequential": 1,
      "id": 11,
      "relationship_type_id": 13,
      "custom_27": 2,
      "custom_28": "blablabla",
      "custom_29": "blablabla",
      "custom_30": "blablabla"
  }).done(function(result) {
      // do something
  });
  </code></pre>
  
  <p>And here is my "result" :</p>
  
  <pre><code>{
      "error_code": "syntax error",
      "sql": "SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN (  ) AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (11) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (1' at line 1]",
      "tip": "add debug=1 to your API call to have more info about the error",
      "is_error": 1,
      "error_message": "DB Constraint Violation - possibly relationship_type_id should possibly be marked as mandatory for this API. If so, please raise a bug report",
      "debug_information": "SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN (  ) AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (11) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (1' at line 1]"
  }
  </code></pre>
  
  <p>Everything was fine yesterday...</p>
  
  <p>Here is the backtrace :</p>
  
  <pre><code>#0 [internal function]: CRM_Core_Error::exceptionHandler(Object(DB_Error))\n
  #1 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func(Array, Object(DB_Error))\n
  #2 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB.php(976): PEAR_Error-&gt;PEAR_Error('DB Error: synta...', -2, 16, Array, 'SELECT COUNT(*)...')\n
  #3 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error-&gt;DB_Error(-2, 16, Array, 'SELECT COUNT(*)...')\n
  #4 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR-&gt;raiseError(NULL, -2, NULL, NULL, 'SELECT COUNT(*)...', 'DB_Error', true)\n
  #5 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/mysql.php(899): DB_common-&gt;raiseError(-2, NULL, NULL, NULL, '1064 ** You hav...')\n
  #6 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/mysql.php(328): DB_mysql-&gt;mysqlRaiseError()\n
  #7 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql-&gt;simpleQuery('SELECT COUNT(*)...')\n
  #8 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/DataObject.php(2442): DB_common-&gt;query('SELECT COUNT(*)...')\n
  #9 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/DataObject.php(1634): DB_DataObject-&gt;_query('SELECT COUNT(*)...')\n
  #10 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/DAO.php(325): DB_DataObject-&gt;query('SELECT COUNT(*)...')\n
  #11 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/DAO.php(1221): CRM_Core_DAO-&gt;query('SELECT COUNT(*)...', true)\n
  #12 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(1623): CRM_Core_DAO::singleValueQuery('SELECT COUNT(*)...', Array)\n
  #13 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(1590): CRM_Contact_BAO_Relationship::isDeleteRelatedMembership(Array, '870', 2, '13', Array)\n
  #14 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(715): CRM_Contact_BAO_Relationship::relatedMemberships('870', Array, Array, 2, true)\n
  #15 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(79): CRM_Contact_BAO_Relationship::disableEnableRelationship(11, 32, Array, Array, true)\n
  #16 [internal function]: CRM_Contact_BAO_Relationship::create(Array, Array)\n
  #17 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/v3/utils.php(1284): call_user_func_array(Array, Array)\n
  #18 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/v3/Relationship.php(47): _civicrm_api3_basic_create('CRM_Contact_BAO...', Array, 'Relationship')\n
  #19 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_relationship_create(Array)\n
  #20 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/Civi/API/Kernel.php(96): Civi\\API\\Provider\\MagicFunctionProvider-&gt;invoke(Array)\n
  #21 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/api.php(23): Civi\\API\\Kernel-&gt;run('Relationship', 'create', Array, NULL)\n
  #22 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Utils/REST.php(402): civicrm_api('Relationship', 'create', Array)\n
  #23 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Utils/REST.php(638): CRM_Utils_REST::process(Array, Array)\n
  #24 [internal function]: CRM_Utils_REST::ajax()\n
  #25 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(278): call_user_func(Array)\n
  #26 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(86): CRM_Core_Invoke::runItem(Array)\n
  #27 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(54): CRM_Core_Invoke::_invoke(Array)\n
  #28 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/drupal/civicrm.module(489): CRM_Core_Invoke::invoke(Array)\n
  #29 [internal function]: civicrm_invoke('ajax', 'rest')\n
  #30 /var/aegir/platforms/sfd_d7v37/includes/menu.inc(519): call_user_func_array('civicrm_invoke', Array)\n
  #31 /var/aegir/platforms/sfd_d7v37/index.php(21): menu_execute_active_handler()\n
  #32 {main}
  </code></pre>
  
  <p>Any help ?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-08T08:32:12.397Z
Comments.Text: I just tested it on http://d46.demo.civicrm.org/ and this is working just fine...
Comments.UserDisplayName: matthias de MAUROY
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-08T08:39:38.180Z
Comments.Text: Nevermind... seems that the relationship was corrupted so I tried it using a new relationship and this is working just fine !
Comments.UserDisplayName: matthias de MAUROY
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-08T17:38:33.067Z
Comments.Text: Why do you need to specify the relationship_type_id in an update call? Are you changing the type of an existing relationship?
Comments.UserDisplayName: DaveFF
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-09T01:39:22.617Z
Comments.Text: Please write an answer to this question documenting what you did about your corrupted relationship type. Others might find it useful.
Comments.UserDisplayName: Andie Hunt
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-20T09:52:40.717Z
Comments.Text: I'm very sorry to say that I didn't do anything... I just tried to modify this specific relationship and unfortunately couldn't do it. So i just deleted this relationship and tried again with another one with success this time.
Comments.UserDisplayName: matthias de MAUROY
Tags: <api><relationships><ajax><javascript>
Title: Why do I have an error when trying to update relationship using CiviCRM API
ThreadText: # Why do I have an error when trying to update relationship using CiviCRM API
  
  (Asked by: username_0 on 2015-10-08)
  
  Since this morning I'm running into something strange when using the API to update a relationship.
  
  Here is my code :
  
  ```
  CRM.api3('Relationship', 'create', {
      "sequential": 1,
      "id": 11,
      "relationship_type_id": 13,
      "custom_27": 2,
      "custom_28": "blablabla",
      "custom_29": "blablabla",
      "custom_30": "blablabla"
  }).done(function(result) {
      // do something
  });
  
  ```
  
  And here is my "result" :
  
  ```
  {
      "error_code": "syntax error",
      "sql": "SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN (  ) AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (11) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (1' at line 1]",
      "tip": "add debug=1 to your API call to have more info about the error",
      "is_error": 1,
      "error_message": "DB Constraint Violation - possibly relationship_type_id should possibly be marked as mandatory for this API. If so, please raise a bug report",
      "debug_information": "SELECT COUNT(*) FROM civicrm_relationship WHERE relationship_type_id IN (  ) AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (11) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND contact_id_a IN ( 870, 2 ) AND contact_id_b IN ( 870, 2 ) AND id NOT IN (1' at line 1]"
  }
  
  ```
  
  Everything was fine yesterday...
  
  Here is the backtrace :
  
  ```
  #0 [internal function]: CRM_Core_Error::exceptionHandler(Object(DB_Error))\n
  #1 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func(Array, Object(DB_Error))\n
  #2 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB.php(976): PEAR_Error->PEAR_Error('DB Error: synta...', -2, 16, Array, 'SELECT COUNT(*)...')\n
  #3 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-2, 16, Array, 'SELECT COUNT(*)...')\n
  #4 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -2, NULL, NULL, 'SELECT COUNT(*)...', 'DB_Error', true)\n
  #5 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/mysql.php(899): DB_common->raiseError(-2, NULL, NULL, NULL, '1064 ** You hav...')\n
  #6 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/mysql.php(328): DB_mysql->mysqlRaiseError()\n
  #7 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery('SELECT COUNT(*)...')\n
  #8 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/DataObject.php(2442): DB_common->query('SELECT COUNT(*)...')\n
  #9 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/packages/DB/DataObject.php(1634): DB_DataObject->_query('SELECT COUNT(*)...')\n
  #10 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/DAO.php(325): DB_DataObject->query('SELECT COUNT(*)...')\n
  #11 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/DAO.php(1221): CRM_Core_DAO->query('SELECT COUNT(*)...', true)\n
  #12 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(1623): CRM_Core_DAO::singleValueQuery('SELECT COUNT(*)...', Array)\n
  #13 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(1590): CRM_Contact_BAO_Relationship::isDeleteRelatedMembership(Array, '870', 2, '13', Array)\n
  #14 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(715): CRM_Contact_BAO_Relationship::relatedMemberships('870', Array, Array, 2, true)\n
  #15 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php(79): CRM_Contact_BAO_Relationship::disableEnableRelationship(11, 32, Array, Array, true)\n
  #16 [internal function]: CRM_Contact_BAO_Relationship::create(Array, Array)\n
  #17 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/v3/utils.php(1284): call_user_func_array(Array, Array)\n
  #18 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/v3/Relationship.php(47): _civicrm_api3_basic_create('CRM_Contact_BAO...', Array, 'Relationship')\n
  #19 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_relationship_create(Array)\n
  #20 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/Civi/API/Kernel.php(96): Civi\\API\\Provider\\MagicFunctionProvider->invoke(Array)\n
  #21 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/api/api.php(23): Civi\\API\\Kernel->run('Relationship', 'create', Array, NULL)\n
  #22 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Utils/REST.php(402): civicrm_api('Relationship', 'create', Array)\n
  #23 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Utils/REST.php(638): CRM_Utils_REST::process(Array, Array)\n
  #24 [internal function]: CRM_Utils_REST::ajax()\n
  #25 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(278): call_user_func(Array)\n
  #26 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(86): CRM_Core_Invoke::runItem(Array)\n
  #27 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/CRM/Core/Invoke.php(54): CRM_Core_Invoke::_invoke(Array)\n
  #28 /var/aegir/platforms/sfd_d7v37/sites/all/modules/civicrm/drupal/civicrm.module(489): CRM_Core_Invoke::invoke(Array)\n
  #29 [internal function]: civicrm_invoke('ajax', 'rest')\n
  #30 /var/aegir/platforms/sfd_d7v37/includes/menu.inc(519): call_user_func_array('civicrm_invoke', Array)\n
  #31 /var/aegir/platforms/sfd_d7v37/index.php(21): menu_execute_active_handler()\n
  #32 {main}
  
  ```
  
  Any help ?
  
  **Tags:** api, relationships, ajax, javascript
  
  > **Comments:**
  > **username_0**: I just tested it on http://d46.demo.civicrm.org/ and this is working just fine...  
  > **username_0**: Nevermind... seems that the relationship was corrupted so I tried it using a new relationship and this is working just fine !  
  > **username_1**: Why do you need to specify the relationship_type_id in an update call? Are you changing the type of an existing relationship?  
  > **username_2**: Please write an answer to this question documenting what you did about your corrupted relationship type. Others might find it useful.  
  > **username_0**: I'm very sorry to say that I didn't do anything... I just tried to modify this specific relationship and unfortunately couldn't do it. So i just deleted this relationship and tried again with another one with success this time.  
  
  ---
  
  ## 0 answers
  
  