Returns the name of the relation type which is usable in SQL or false if unknown type.

This function can be used by some database handlers which can operate on relation types using SQL.

@access protected
@param int $relationType
@return bool
320440
function relationName( $relationType )
    {
        $names = array( eZDBInterface::RELATION_TABLE => 'TABLE',
                        eZDBInterface::RELATION_SEQUENCE => 'SEQUENCE',
                        eZDBInterface::RELATION_TRIGGER => 'TRIGGER',
                        eZDBInterface::RELATION_VIEW => 'VIEW',
                        eZDBInterface::RELATION_INDEX => 'INDEX' );
        if ( !isset( $names[$relationType] ) )
            return false;
        return $names[$relationType];
    }
826948
public function lazyLoad($instance, $relation_name)
    {
        if (($relation = $this->get($instance, $relation_name)) === false) {
            throw new InvalidValueException($relation);
        }

        $type = $relation->type;
        $referenceModel = $relation->referenceModel;
        $valueField = $relation->valueField;
        if ($type === Relation::TYPE_HAS_ONE) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(false);
        } elseif ($type === Relation::TYPE_BELONGS_TO) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(false);
        } elseif ($type === Relation::TYPE_HAS_MANY) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(true);
        } elseif ($type === Relation::TYPE_HAS_MANY_TO_MANY) {
            $ids = $instance::values($relation->keyField, [$valueField => $instance->$valueField]);
            /** @var \ManaPHP\Model $referenceInstance */
            $referenceInstance = is_string($referenceModel) ? new $referenceModel : $referenceModel;
            return $referenceModel::query()->whereIn($referenceInstance->getPrimaryKey(), $ids)->setFetchType(true);
        } elseif ($type === Relation::TYPE_HAS_MANY_VIA) {
            $via = $relation->keyField;
            /** @var \ManaPHP\Model $reference */
            $reference = new $referenceModel();
            $ids = $via::values($reference->getPrimaryKey(), [$valueField => $instance->$valueField]);
            return $referenceModel::query()->whereIn($reference->getPrimaryKey(), $ids)->setFetchType(true);
        } else {
            throw  new NotSupportedException(['unknown relation type: :type', 'type' => $type]);
        }
    }
1329488
public function getConnection($type = Propel::CONNECTION_READ)
    {
        $databaseName = constant($this->getPeerClass() . '::DATABASE_NAME');

        return Propel::getConnection($databaseName, $type);
    }
1043300
public function getRelationValue($object, $relationName)
    {
        $this->assertObjectInstance($object);

        return $this->getRelation($relationName)->get($object);
    }
1057476
public function findRelation($entity, $relationName, $orderColumn = null, $orderType = null) {
        $this->load();
        $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
        $relation = $mapper->getRelation($relationName);
        $relationMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

        $selectQuery = "SELECT tmain.* FROM `" . $relationMapper->getTable() . "` tmain ";
        $joinQuery = QueryBuilder::buildJoinRelationQuery($relation, "tmain", "j1");
        $whereQuery = "WHERE j1." . $relation->getLocalColumn() . " = '" . $entity->getId() . "'";

        $orderQuery = "";
        if (!is_null($orderColumn)) {
            $orderQuery .= "ORDER BY $orderColumn ";
            if (!is_null($orderType)) {
                $orderQuery .= "$orderType";
            } else {
                $orderQuery .= "ASC";
            }
        }

        $query = $selectQuery . $joinQuery . $whereQuery . $orderQuery;
        $queryResult = $this->getDataSource()->query($query);
        if ($queryResult) {
            $collection = new Collection($relationMapper->getClass(), $queryResult, $relationMapper);
        } else {
            $collection = new Collection($relationMapper->getClass(), array(), $relationMapper);
        }

        return $collection;
    }
528208
public function getType($type)
    {
        $aliases = array(
            'int'    => 'integer',
            'bool'   => 'boolean',
            'double' => 'float',
            'object' => '\\stdClass'
        );
        $default = array(
            'integer', 'boolean', 'float', '\\stdClass', 'callable', 'string', 'resource', 'void', 'mixed'
        );
        $typeHintEnabled = false;

        if (isset($aliases[$type])) {
            $type = $aliases[$type];
        }

        if (!in_array($type, $default)) {
            $typeHintEnabled = true;
        }

        return array(
            'name' => $type,
            'hint' => $typeHintEnabled
        );
    }
267944
public function getRelationType($component)
    {
        $types = array('has_one', 'has_many', 'many_many', 'belongs_many_many', 'belongs_to');
        $config = $this->config();
        foreach ($types as $type) {
            $relations = $config->get($type);
            if ($relations && isset($relations[$component])) {
                return $type;
            }
        }
        return null;
    }
604450
public function getRelationClass($relationName)
    {
        // Parse many_many
        $manyManyComponent = $this->getSchema()->manyManyComponent(static::class, $relationName);
        if ($manyManyComponent) {
            return $manyManyComponent['childClass'];
        }

        // Go through all relationship configuration fields.
        $config = $this->config();
        $candidates = array_merge(
            ($relations = $config->get('has_one')) ? $relations : array(),
            ($relations = $config->get('has_many')) ? $relations : array(),
            ($relations = $config->get('belongs_to')) ? $relations : array()
        );

        if (isset($candidates[$relationName])) {
            $remoteClass = $candidates[$relationName];

            // If dot notation is present, extract just the first part that contains the class.
            if (($fieldPos = strpos($remoteClass, '.')) !== false) {
                return substr($remoteClass, 0, $fieldPos);
            }

            // Otherwise just return the class
            return $remoteClass;
        }

        return null;
    }
861208
public function getRelationshipType($to)
    {
        $map = $this->relationshipTypeMap;
        if (isset($map[$to])) {
            return $map[$to];
        }

        return false;
    }
864226
public function getType()
    {
        if ($this->type === null) {
            $this->type = $this->getRelated('type');
        }
        return $this->type;
    }
487092
public function mapRelatives()
    {
        $relations = collect($this->relations());

        if ($relations->isEmpty()) {
            return false;
        }

        return $this->items = collect($this->all())
            ->map(function ($value, $key) use ($relations) {
                if ($relations->has($key)) {
                    $className = $relations->get($key);

                    return new $className($value);
                }

                return $value;
            })
            ->all();
    }
1240899
public function isRelationLoaded($relationName)
    {
        if (!isset($this->loadedRelations[ $relationName ])) {
            throw new \OutOfBoundsException("Unknown relation: {$relationName}");
        }

        return $this->loadedRelations[ $relationName ];
    }
1021710
public function getRelationTable()
    {
        if (is_null($this->_relationTable)) {
            $names = [
                $this->getEntity()->getTableName(),
                Entity\Manager::getInstance()
                    ->get($this->_relatedEntity)
                    ->getEntity()->getTableName()
            ];
            asort($names);
            $this->setRelationTable(implode('_', $names));
        }
        return $this->_relationTable;
    }
291386
private function buildRelationsTree($relationType)
    {
        $filter = new ArrayNodeDefinition($relationType);

        $filter
            ->validate()
                ->ifTrue(
                    function ($v) {
                        return empty($v['include']) && empty($v['exclude']);
                    }
                )
                ->thenInvalid('Relation must have "include" or "exclude" fields specified.')
            ->end()
            ->validate()
                ->ifTrue(
                    function ($v) {
                        return !empty($v['include']) && !empty($v['exclude']);
                    }
                )
                ->thenInvalid('Relation must have only "include" or "exclude" fields specified.')
            ->end()
            ->children()
                ->arrayNode('include')
                    ->beforeNormalization()
                        ->ifString()
                        ->then(
                            function ($v) {
                                return [$v];
                            }
                        )->end()
                    ->prototype('scalar')->end()
                ->end()
                ->arrayNode('exclude')
                    ->beforeNormalization()
                        ->ifString()
                        ->then(
                            function ($v) {
                                return [$v];
                            }
                        )
                    ->end()
                    ->prototype('scalar')->end()
                ->end()
            ->end();

        return $filter;
    }
1264116
public function relationFieldName($type, $name) {
		$fieldName = Inflector::underscore($name);
		if (preg_match('/Many$/', $type)) {
			$fieldName = Inflector::pluralize($fieldName);
		} else {
			$fieldName = Inflector::singularize($fieldName);
		}
		return $fieldName;
	}
380933
public function connectionType($which_connection='')
    {
        if ($which_connection == '') {
            $which_connection=$this->default_db;
        }
        if ($this->isConnected($which_connection)) {
            $reflect = new \ReflectionClass($this->connections[$which_connection]);
            if (substr($reflect->name, 0, 6) == 'ADODB_') {
                return substr($reflect->name, 6);
            }
        }

        return 'unknown';
    }
91273
public static function getTypeName($type)
    {
        return isset(self::$names[$type])
            ? self::$names[$type]
            : null;
    }