public function bindCollection(Collection $collection, array $compareKeys, $propertyName)
    {
        $reflection = new \ReflectionClass($collection);

        $fromKey = key($compareKeys);
        $toKey = $compareKeys[$fromKey];

        $collection = $collection->groupByField($fromKey);

        foreach ($this as $entity) {
            if (!isset($entity->$propertyName)) {
                $entity->$propertyName = new $reflection->name;
            }

            if (!isset($entity->$toKey) || ($value = $entity->$toKey) === null) {
                continue; //do not try to bind to null or non existing property
            }

            if (isset($collection[$value])) {
                $entity->$propertyName->append($collection[$value]);
            }
        }
        return $this;
    }
public function bindCollection(Collection $collection, array $compareKeys, $propertyName)
    {
        $reflection = new \ReflectionClass($collection);

        $fromKey = key($compareKeys);
        $toKey = $compareKeys[$fromKey];

        $collection = $collection->groupByField($fromKey);

        foreach ($this as $entity) {
            if (!isset($entity->$propertyName)) {
                $entity->$propertyName = new $reflection->name;
            }

            if (!isset($entity->$toKey) || ($value = $entity->$toKey) === null) {
                continue; //do not try to bind to null or non existing property
            }

            if (isset($collection[$value])) {
                $entity->$propertyName->append($collection[$value]);
            }
        }
        return $this;
    }
public function bindCollection ( Collection $ collection , array $ compareKeys , $ propertyName ) { $ reflection = new \ ReflectionClass ( $ collection ) ; $ fromKey = key ( $ compareKeys ) ; $ toKey = $ compareKeys [ $ fromKey ] ; $ collection = $ collection -> groupByField ( $ fromKey ) ; foreach ( $ this as $ entity ) { if ( ! isset ( $ entity -> $ propertyName ) ) { $ entity -> $ propertyName = new $ reflection -> name ; } if ( ! isset ( $ entity -> $ toKey ) || ( $ value = $ entity -> $ toKey ) === null ) { continue ; //do not try to bind to null or non existing property } if ( isset ( $ collection [ $ value ] ) ) { $ entity -> $ propertyName -> append ( $ collection [ $ value ] ) ; } } return $ this ; }
Bind two collections

@param Collection $collection collection
@param array $compareKeys The name of the key to compare with from target Collection
@param string $propertyName The nae of new property that will be created in source Collection

@return static
Bind two collections