getRelationship() public method

Returns relationship that property represents
public getRelationship ( ) : LeanMapper\Relationship\BelongsToMany | LeanMapper\Relationship\BelongsToOne | HasMany | HasOne | null
return LeanMapper\Relationship\BelongsToMany | LeanMapper\Relationship\BelongsToOne | LeanMapper\Relationship\HasMany | LeanMapper\Relationship\HasOne | null
Ejemplo n.º 1
0
 private function traverseToRelatedEntity(&$currentTable, &$currentTableAlias, Property $property)
 {
     if (!$property->hasRelationship()) {
         $entityClass = $this->mapper->getEntityClass($currentTable);
         throw new InvalidRelationshipException("Property '{$property->getName()}' in entity '{$entityClass}' doesn't have any relationship.");
     }
     $implicitFilters = array();
     $propertyType = $property->getType();
     if (is_subclass_of($propertyType, 'LeanMapper\\Entity')) {
         $caller = new Caller($this, $property);
         $implicitFilters = $this->mapper->getImplicitFilters($property->getType(), $caller);
     }
     $relationship = $property->getRelationship();
     if ($relationship instanceof Relationship\HasOne) {
         $targetTable = $relationship->getTargetTable();
         $targetTablePrimaryKey = $this->mapper->getPrimaryKey($targetTable);
         $referencingColumn = $relationship->getColumnReferencingTargetTable();
         // Join table.
         $targetTableAlias = $this->joinRelatedTable($currentTableAlias, $referencingColumn, $targetTable, $targetTablePrimaryKey, $implicitFilters, FALSE);
     } elseif ($relationship instanceof Relationship\BelongsTo) {
         // BelongsToOne, BelongsToMany
         $targetTable = $relationship->getTargetTable();
         $sourceTablePrimaryKey = $this->mapper->getPrimaryKey($currentTable);
         $referencingColumn = $relationship->getColumnReferencingSourceTable();
         // Join table.
         $targetTableAlias = $this->joinRelatedTable($currentTableAlias, $sourceTablePrimaryKey, $targetTable, $referencingColumn, $implicitFilters);
     } elseif ($relationship instanceof Relationship\HasMany) {
         $sourceTablePrimaryKey = $this->mapper->getPrimaryKey($currentTable);
         $relationshipTable = $relationship->getRelationshipTable();
         $sourceReferencingColumn = $relationship->getColumnReferencingSourceTable();
         $targetReferencingColumn = $relationship->getColumnReferencingTargetTable();
         $targetTable = $relationship->getTargetTable();
         $targetTablePrimaryKey = $this->mapper->getPrimaryKey($targetTable);
         // Join tables.
         // Don't apply filters on relationship table.
         $relationshipTableAlias = $this->joinRelatedTable($currentTableAlias, $sourceTablePrimaryKey, $relationshipTable, $sourceReferencingColumn);
         $targetTableAlias = $this->joinRelatedTable($relationshipTableAlias, $targetReferencingColumn, $targetTable, $targetTablePrimaryKey, $implicitFilters, FALSE);
     } else {
         throw new InvalidRelationshipException('Unknown relationship type. ' . get_class($relationship) . ' given.');
     }
     $currentTable = $targetTable;
     $currentTableAlias = $targetTableAlias;
     return $this->getPropertiesByTable($targetTable);
 }