src/Components/DbSchemaExtras.php
public function setSchemaVirtualRelationships($relationships)
    {
        if (empty($relationships)) {
            return;
        }

        foreach ($relationships as $extra) {
            if (!empty($extra['ref_table']) && empty($extra['ref_service_id'])) {
                // don't allow empty ref_service_id into the database, needs to be searchable from other services
                $extra['ref_service_id'] = $this->getServiceId();
            }
            if (!empty($extra['junction_table']) && empty($extra['junction_service_id'])) {
                // don't allow empty junction_service_id into the database, needs to be searchable from other services
                $extra['junction_service_id'] = $this->getServiceId();
            }
            DbVirtualRelationship::updateOrCreate(
                [
                    'type'                => array_get($extra, 'type'),
                    'service_id'          => $this->getServiceId(),
                    'table'               => array_get($extra, 'table'),
                    'field'               => array_get($extra, 'field'),
                    'ref_service_id'      => array_get($extra, 'ref_service_id'),
                    'ref_table'           => array_get($extra, 'ref_table'),
                    'ref_field'           => array_get($extra, 'ref_field'),
                    'junction_service_id' => array_get($extra, 'junction_service_id'),
                    'junction_table'      => array_get($extra, 'junction_table'),
                    'junction_field'      => array_get($extra, 'junction_field'),
                    'junction_ref_field'  => array_get($extra, 'junction_ref_field'),
                ],
                array_only($extra,
                    [
                        'ref_on_update',
                        'ref_on_delete',
                    ]
                )
            );
        }
    }
public function setSchemaVirtualRelationships($relationships)
    {
        if (empty($relationships)) {
            return;
        }

        foreach ($relationships as $extra) {
            if (!empty($extra['ref_table']) && empty($extra['ref_service_id'])) {
                // don't allow empty ref_service_id into the database, needs to be searchable from other services
                $extra['ref_service_id'] = $this->getServiceId();
            }
            if (!empty($extra['junction_table']) && empty($extra['junction_service_id'])) {
                // don't allow empty junction_service_id into the database, needs to be searchable from other services
                $extra['junction_service_id'] = $this->getServiceId();
            }
            DbVirtualRelationship::updateOrCreate(
                [
                    'type'                => array_get($extra, 'type'),
                    'service_id'          => $this->getServiceId(),
                    'table'               => array_get($extra, 'table'),
                    'field'               => array_get($extra, 'field'),
                    'ref_service_id'      => array_get($extra, 'ref_service_id'),
                    'ref_table'           => array_get($extra, 'ref_table'),
                    'ref_field'           => array_get($extra, 'ref_field'),
                    'junction_service_id' => array_get($extra, 'junction_service_id'),
                    'junction_table'      => array_get($extra, 'junction_table'),
                    'junction_field'      => array_get($extra, 'junction_field'),
                    'junction_ref_field'  => array_get($extra, 'junction_ref_field'),
                ],
                array_only($extra,
                    [
                        'ref_on_update',
                        'ref_on_delete',
                    ]
                )
            );
        }
    }
@param array $relationships

@return void