Spot\Mapper::hasManyThrough PHP Method

hasManyThrough() public method

Relation: HasManyThrough
public hasManyThrough ( EntityInterface $entity, $hasManyEntity, $throughEntity, $selectField, $whereField )
$entity EntityInterface
    public function hasManyThrough(EntityInterface $entity, $hasManyEntity, $throughEntity, $selectField, $whereField)
    {
        $localPkField = $this->primaryKeyField();
        $localValue = $entity->{$localPkField};
        if (!is_subclass_of($hasManyEntity, 'Spot\\EntityInterface')) {
            throw new \InvalidArgumentException("Related entity name must be a " . "valid entity that extends Spot\\Entity. Given '" . $hasManyEntity . "'.");
        }
        if (!is_subclass_of($throughEntity, 'Spot\\EntityInterface')) {
            throw new \InvalidArgumentException("Related entity name must be a " . "valid entity that extends Spot\\Entity. Given '" . $throughEntity . "'.");
        }
        return new Relation\HasManyThrough($this, $hasManyEntity, $throughEntity, $selectField, $whereField, $localValue);
    }

Usage Example

Example #1
0
 public static function relations(Mapper $mapper, Entity $entity)
 {
     return ['tags' => $mapper->hasManyThrough($entity, 'SpotTest\\Entity\\Tag', 'SpotTest\\Entity\\PostTag', 'tag_id', 'post_id'), 'comments' => $mapper->hasMany($entity, 'SpotTest\\Entity\\Post\\Comment', 'post_id')->order(['date_created' => 'ASC']), 'author' => $mapper->belongsTo($entity, 'SpotTest\\Entity\\Author', 'author_id')];
 }
All Usage Examples Of Spot\Mapper::hasManyThrough