src/Resources/DbSchemaResource.php
public function createTableRelated($table_name, $related)
    {
        if (!is_array($related) || empty($related)) {
            return [];
        }

        if (!isset($related[0])) {
            // single record possibly passed in without wrapper array
            $related = [$related];
        }

        $extra = [];
        $virtual = [];
        foreach ($related as $relation) {
            $this->cleanClientRelation($relation);
            // clean out extras
            $extraNew = array_only($relation, $this->relatedExtras);
            if (!empty($extraNew['alias']) || !empty($extraNew['label']) || !empty($extraNew['description']) ||
                !empty($extraNew['always_fetch']) || !empty($extraNew['flatten']) ||
                !empty($extraNew['flatten_drop_prefix'])
            ) {
                if (!empty($si = array_get($relation, 'ref_service_id'))) {
                    if ($this->getServiceId() !== $si) {
                        $relation['ref_service'] = ServiceManager::getServiceNameById($si);
                    }
                }
                if (!empty($si = array_get($relation, 'junction_service_id'))) {
                    if (!empty($si) && ($this->getServiceId() !== $si)) {
                        $relation['junction_service'] = ServiceManager::getServiceNameById($si);
                    }
                }
                $extraNew['table'] = $table_name;
                $extraNew['relationship'] = RelationSchema::buildName($relation);
                $extra[] = $extraNew;
            }

            // only virtual
            if (boolval(array_get($relation, 'is_virtual'))) {
                $relation = array_except($relation, $this->relatedExtras);
                $relation['table'] = $table_name;
                $virtual[] = $relation;
            } else {
                // todo create foreign keys here eventually as well?
            }
        }

        return [
            'related_extras'    => $extra,
            'virtual_relations' => $virtual,
        ];
    }
public function createTableRelated($table_name, $related)
    {
        if (!is_array($related) || empty($related)) {
            return [];
        }

        if (!isset($related[0])) {
            // single record possibly passed in without wrapper array
            $related = [$related];
        }

        $extra = [];
        $virtual = [];
        foreach ($related as $relation) {
            $this->cleanClientRelation($relation);
            // clean out extras
            $extraNew = array_only($relation, $this->relatedExtras);
            if (!empty($extraNew['alias']) || !empty($extraNew['label']) || !empty($extraNew['description']) ||
                !empty($extraNew['always_fetch']) || !empty($extraNew['flatten']) ||
                !empty($extraNew['flatten_drop_prefix'])
            ) {
                if (!empty($si = array_get($relation, 'ref_service_id'))) {
                    if ($this->getServiceId() !== $si) {
                        $relation['ref_service'] = ServiceManager::getServiceNameById($si);
                    }
                }
                if (!empty($si = array_get($relation, 'junction_service_id'))) {
                    if (!empty($si) && ($this->getServiceId() !== $si)) {
                        $relation['junction_service'] = ServiceManager::getServiceNameById($si);
                    }
                }
                $extraNew['table'] = $table_name;
                $extraNew['relationship'] = RelationSchema::buildName($relation);
                $extra[] = $extraNew;
            }

            // only virtual
            if (boolval(array_get($relation, 'is_virtual'))) {
                $relation = array_except($relation, $this->relatedExtras);
                $relation['table'] = $table_name;
                $virtual[] = $relation;
            } else {
                // todo create foreign keys here eventually as well?
            }
        }

        return [
            'related_extras'    => $extra,
            'virtual_relations' => $virtual,
        ];
    }
@param string $table_name
@param array  $related

@throws \Exception
@return array