Spot\Mapper::hasMany PHP Method

hasMany() public method

Relation: HasMany
public hasMany ( EntityInterface $entity, $entityName, $foreignKey, $localValue = null )
$entity EntityInterface
    public function hasMany(EntityInterface $entity, $entityName, $foreignKey, $localValue = null)
    {
        if ($localValue === null) {
            $localValue = $this->primaryKey($entity);
        }
        if (!is_subclass_of($entityName, 'Spot\\EntityInterface')) {
            throw new \InvalidArgumentException("Related entity name must be a " . "valid entity that extends Spot\\Entity. Given '" . $entityName . "'.");
        }
        return new Relation\HasMany($this, $entityName, $foreignKey, $this->primaryKeyField(), $localValue);
    }

Usage Example

Ejemplo n.º 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')];
 }