1

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 ?

5
  • I just tested it on d46.demo.civicrm.org and this is working just fine... Oct 8 '15 at 8:32
  • Nevermind... seems that the relationship was corrupted so I tried it using a new relationship and this is working just fine ! Oct 8 '15 at 8:39
  • Why do you need to specify the relationship_type_id in an update call? Are you changing the type of an existing relationship?
    – DaveFF
    Oct 8 '15 at 17:38
  • Please write an answer to this question documenting what you did about your corrupted relationship type. Others might find it useful.
    – Andie Hunt
    Oct 9 '15 at 1:39
  • 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. Oct 20 '15 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.