LeanMapper\Reflection\Property::hasRelationship PHP Method

hasRelationship() public method

Tells whether property represents relationship
public hasRelationship ( ) : boolean
return boolean
    public function hasRelationship()
    {
        return $this->relationship !== null;
    }

Usage Example

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);
 }