Skip to content

Commit

Permalink
APIv4 - Remove unused backreferences from SchemaMap
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jul 4, 2021
1 parent 5095a7b commit eb1f650
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions Civi/Api4/Service/Schema/SchemaMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ private function loadTables(SchemaMap $map) {
$this->addCustomFields($map, $table, $data['name']);
}
}

$this->addBackReferences($map);
}

/**
Expand Down Expand Up @@ -98,49 +96,6 @@ private function addJoins(Table $table, $field, array $data) {
}
}

/**
* Loop through existing links and provide link from the other side
*
* @param SchemaMap $map
*/
private function addBackReferences(SchemaMap $map) {
foreach ($map->getTables() as $table) {
foreach ($table->getTableLinks() as $link) {
$target = $map->getTableByName($link->getTargetTable());
$tableName = $link->getBaseTable();
// Exclude custom field tables
if (strpos($link->getTargetTable(), 'civicrm_value_') !== 0 && strpos($link->getBaseTable(), 'civicrm_value_') !== 0) {
$plural = str_replace('civicrm_', '', $this->getPlural($tableName));
$joinable = new Joinable($tableName, $link->getBaseColumn(), $plural);
$joinable->setJoinType($joinable::JOIN_TYPE_ONE_TO_MANY);
$target->addTableLink($link->getTargetColumn(), $joinable);
}
}
}
}

/**
* Simple implementation of pluralization.
* Could be replaced with symfony/inflector
*
* @param string $singular
*
* @return string
*/
private function getPlural($singular) {
$last_letter = substr($singular, -1);
switch ($last_letter) {
case 'y':
return substr($singular, 0, -1) . 'ies';

case 's':
return $singular . 'es';

default:
return $singular . 's';
}
}

/**
* @param \Civi\Api4\Service\Schema\SchemaMap $map
* @param \Civi\Api4\Service\Schema\Table $baseTable
Expand Down

0 comments on commit eb1f650

Please sign in to comment.