source/Spiral/ORM/Helpers/RelationOptions.php
protected function proposedOptions(array $userOptions): array
    {
        $source = $this->definition->sourceContext();

        $proposed = [
            //Relation name
            'relation:name'     => $this->definition->getName(),

            //Relation name in plural form
            'relation:plural'   => Inflector::pluralize($this->definition->getName()),

            //Relation name in singular form
            'relation:singular' => Inflector::singularize($this->definition->getName()),

            //Parent record role name
            'source:role'       => $source->getRole(),

            //Parent record table name
            'source:table'      => $source->getTable(),

            //Parent record primary key
            'source:primaryKey' => $source->getPrimary()->getName(),
        ];

        //Some options may use values declared in other definition fields
        $aliases = [
            Record::OUTER_KEY   => 'outerKey',
            Record::INNER_KEY   => 'innerKey',
            Record::PIVOT_TABLE => 'pivotTable',
        ];

        foreach ($aliases as $property => $alias) {
            if (isset($userOptions[$property])) {
                //Let's create some default options based on user specified values
                $proposed['option:' . $alias] = $userOptions[$property];
            }
        }

        if (!empty($this->definition->targetContext())) {
            $target = $this->definition->targetContext();

            $proposed = $proposed + [
                    //Outer role name
                    'target:role'       => $target->getRole(),

                    //Outer record table
                    'target:table'      => $target->getTable(),

                    //Outer record primary key
                    'target:primaryKey' => !empty($target->getPrimary()) ? $target->getPrimary()->getName() : '',
                ];
        }

        return $proposed;
    }
protected function proposedOptions(array $userOptions): array
    {
        $source = $this->definition->sourceContext();

        $proposed = [
            //Relation name
            'relation:name'     => $this->definition->getName(),

            //Relation name in plural form
            'relation:plural'   => Inflector::pluralize($this->definition->getName()),

            //Relation name in singular form
            'relation:singular' => Inflector::singularize($this->definition->getName()),

            //Parent record role name
            'source:role'       => $source->getRole(),

            //Parent record table name
            'source:table'      => $source->getTable(),

            //Parent record primary key
            'source:primaryKey' => $source->getPrimary()->getName(),
        ];

        //Some options may use values declared in other definition fields
        $aliases = [
            Record::OUTER_KEY   => 'outerKey',
            Record::INNER_KEY   => 'innerKey',
            Record::PIVOT_TABLE => 'pivotTable',
        ];

        foreach ($aliases as $property => $alias) {
            if (isset($userOptions[$property])) {
                //Let's create some default options based on user specified values
                $proposed['option:' . $alias] = $userOptions[$property];
            }
        }

        if (!empty($this->definition->targetContext())) {
            $target = $this->definition->targetContext();

            $proposed = $proposed + [
                    //Outer role name
                    'target:role'       => $target->getRole(),

                    //Outer record table
                    'target:table'      => $target->getTable(),

                    //Outer record primary key
                    'target:primaryKey' => !empty($target->getPrimary()) ? $target->getPrimary()->getName() : '',
                ];
        }

        return $proposed;
    }
protected function proposedOptions ( array $ userOptions ) : array { $ source = $ this -> definition -> sourceContext ( ) ; $ proposed = [ //Relation name 'relation:name' => $ this -> definition -> getName ( ) , //Relation name in plural form 'relation:plural' => Inflector :: pluralize ( $ this -> definition -> getName ( ) ) , //Relation name in singular form 'relation:singular' => Inflector :: singularize ( $ this -> definition -> getName ( ) ) , //Parent record role name 'source:role' => $ source -> getRole ( ) , //Parent record table name 'source:table' => $ source -> getTable ( ) , //Parent record primary key 'source:primaryKey' => $ source -> getPrimary ( ) -> getName ( ) , ] ; //Some options may use values declared in other definition fields $ aliases = [ Record :: OUTER_KEY => 'outerKey' , Record :: INNER_KEY => 'innerKey' , Record :: PIVOT_TABLE => 'pivotTable' , ] ; foreach ( $ aliases as $ property => $ alias ) { if ( isset ( $ userOptions [ $ property ] ) ) { //Let's create some default options based on user specified values $ proposed [ 'option:' . $ alias ] = $ userOptions [ $ property ] ; } } if ( ! empty ( $ this -> definition -> targetContext ( ) ) ) { $ target = $ this -> definition -> targetContext ( ) ; $ proposed = $ proposed + [ //Outer role name 'target:role' => $ target -> getRole ( ) , //Outer record table 'target:table' => $ target -> getTable ( ) , //Outer record primary key 'target:primaryKey' => ! empty ( $ target -> getPrimary ( ) ) ? $ target -> getPrimary ( ) -> getName ( ) : '' , ] ; } return $ proposed ; }
Create set of options to specify missing relation definition fields.

@param array $userOptions User options.

@return array
Create set of options to specify missing relation definition fields .