Bravo3\Orm\Mappers\Metadata\Entity::getRelationshipByName PHP Method

getRelationshipByName() public method

Get a relationship by its name, or null if no such relationship exists
public getRelationshipByName ( string $name ) : Relationship | null
$name string
return Relationship | null
    public function getRelationshipByName($name)
    {
        foreach ($this->relationships as $relationship) {
            if ($relationship->getName() == $name) {
                return $relationship;
            }
        }
        return null;
    }

Usage Example

Beispiel #1
0
 /**
  * Get the value of a property on the entity
  *
  * @param string $name
  * @return mixed
  */
 public function getPropertyValue($name)
 {
     if ($column = $this->metadata->getColumnByProperty($name)) {
         $getter = $column->getGetter();
         return $this->entity->{$getter}();
     } elseif ($relationship = $this->metadata->getRelationshipByName($name)) {
         $getter = $relationship->getGetter();
         return $this->entity->{$getter}();
     } else {
         throw new InvalidArgumentException("No column/relationship found for property '" . $name . "'");
     }
 }
All Usage Examples Of Bravo3\Orm\Mappers\Metadata\Entity::getRelationshipByName