Skip to content

Commit

Permalink
Add primaryKey info to daos
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jul 4, 2021
1 parent b675a45 commit eda5da7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
*/
class CRM_Core_DAO extends DB_DataObject {

/**
* Primary key field(s).
*
* @var string[]
*/
public static $_primaryKey = ['id'];

/**
* How many times has this instance been cloned.
*
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Generic/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public static function getInfo() {
$dao = \CRM_Core_DAO_AllCoreTables::getFullName($info['name']);
if ($dao) {
$info['paths'] = $dao::getEntityPaths();
$info['primary_key'] = $dao::$_primaryKey;
$info['icon'] = $dao::$_icon;
$info['label_field'] = $dao::$_labelField;
$info['dao'] = $dao;
Expand Down
10 changes: 10 additions & 0 deletions xml/templates/dao.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
*/
public static $_tableName = '{$table.name}';

{* Only print this variable if it's different than the default in CRM_Core_DAO *}
{if count($table.primaryKey.field) !== 1 || $table.primaryKey.field.0 !== 'id'}
/**
* Primary key field(s).
*
* @var string[]
*/
public static $_primaryKey = [{if $table.primaryKey.field}'{"', '"|implode:$table.primaryKey.field}'{/if}];
{/if}

{if $table.icon}
/**
* Icon associated with this entity.
Expand Down

0 comments on commit eda5da7

Please sign in to comment.