Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20740 - Fix issue with check for custom_nn => ['IS NULL' => 1]. #10512

Merged
merged 4 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Civi/API/Api3SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ protected function buildWhereClause() {
$column_name = $key;
}
elseif (($cf_id = \CRM_Core_BAO_CustomField::getKeyID($key)) != FALSE) {
list($table_name, $column_name) = $this->addCustomField($this->apiFieldSpec['custom_' . $cf_id], 'INNER');
// If we check a custom field on 'IS NULL', it should also work when there is no
// record in the custom value table, see CRM-20740.
$side = empty($value['IS NULL']) ? 'INNER' : 'LEFT OUTER';
list($table_name, $column_name) = $this->addCustomField($this->apiFieldSpec['custom_' . $cf_id], $side);
}
elseif (strpos($key, '.')) {
$fkInfo = $this->addFkField($key, 'INNER');
Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/api/v3/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,27 @@ public function testSearchCustomField() {
$this->customGroupDelete($ids['custom_group_id']);
}

/**
* Check searching on custom fields with IS NULL.
*
* https://issues.civicrm.org/jira/browse/CRM-20740
*/
public function testSearchCustomFieldIsNull() {
// create custom group with custom field on event
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);

// Search for events having NULL as the value for this custom
// field. This should return all events created in setUp.
$check = $this->callAPISuccess($this->_entity, 'get', array(
'custom_' . $ids['custom_field_id'] => array('IS NULL' => 1),
));

$this->assertGreaterThan(0, $check['count']);

$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
}

/**
* Test searching on custom fields returning a contact reference.
*
Expand Down