3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\Api4\Generic\Traits
;
15 * A bridge is a small table that provides an intermediary link between two other tables.
17 * The API can automatically incorporate a Bridge into a join expression.
22 * Adds "bridge" info, which should specify an array of two field names from this entity
24 * This automatic function can be overridden by adding a getInfo function to the api entity class.
28 public static function getInfo() {
29 $info = parent
::getInfo();
31 if (!empty($info['dao'])) {
32 foreach (($info['dao'])::fields() as $field) {
33 if (!empty($field['FKClassName']) ||
$field['name'] === 'entity_id') {
34 $bridgeFields[] = $field['name'];
38 if (count($bridgeFields) === 2) {
40 $bridgeFields[0] => ['to' => $bridgeFields[1]],
41 $bridgeFields[1] => ['to' => $bridgeFields[0]],