lib/Doctrine/ORM/PersistentObject.php
private function add($field, $args)
    {
        $this->initializeDoctrine();

        $property = $this->cm->getProperty($field);

        if (! $property) {
            throw new BadMethodCallException("no field with name '" . $field . "' exists on '" . $this->cm->getClassName() . "'");
        }

        if (! ($property instanceof ToManyAssociationMetadata)) {
            throw new BadMethodCallException('There is no method add' . $field . '() on ' . $this->cm->getClassName());
        }

        $targetClassName = $property->getTargetEntity();

        if (! ($args[0] instanceof $targetClassName)) {
            throw new InvalidArgumentException("Expected persistent object of type '" . $targetClassName . "'");
        }

        if (! ($this->{$field} instanceof Collection)) {
            $this->{$field} = new ArrayCollection($this->{$field} ?: []);
        }

        $this->{$field}->add($args[0]);

        $this->completeOwningSide($property, $args[0]);

        return $this;
    }
private function add($field, $args)
    {
        $this->initializeDoctrine();

        $property = $this->cm->getProperty($field);

        if (! $property) {
            throw new BadMethodCallException("no field with name '" . $field . "' exists on '" . $this->cm->getClassName() . "'");
        }

        if (! ($property instanceof ToManyAssociationMetadata)) {
            throw new BadMethodCallException('There is no method add' . $field . '() on ' . $this->cm->getClassName());
        }

        $targetClassName = $property->getTargetEntity();

        if (! ($args[0] instanceof $targetClassName)) {
            throw new InvalidArgumentException("Expected persistent object of type '" . $targetClassName . "'");
        }

        if (! ($this->{$field} instanceof Collection)) {
            $this->{$field} = new ArrayCollection($this->{$field} ?: []);
        }

        $this->{$field}->add($args[0]);

        $this->completeOwningSide($property, $args[0]);

        return $this;
    }
private function add ( $ field , $ args ) { $ this -> initializeDoctrine ( ) ; $ property = $ this -> cm -> getProperty ( $ field ) ; if ( ! $ property ) { throw new BadMethodCallException ( "no field with name '" . $ field . "' exists on '" . $ this -> cm -> getClassName ( ) . "'" ) ; } if ( ! ( $ property instanceof ToManyAssociationMetadata ) ) { throw new BadMethodCallException ( 'There is no method add' . $ field . '() on ' . $ this -> cm -> getClassName ( ) ) ; } $ targetClassName = $ property -> getTargetEntity ( ) ; if ( ! ( $ args [ 0 ] instanceof $ targetClassName ) ) { throw new InvalidArgumentException ( "Expected persistent object of type '" . $ targetClassName . "'" ) ; } if ( ! ( $ this -> { $ field } instanceof Collection ) ) { $ this -> { $ field } = new ArrayCollection ( $ this -> { $ field } ? : [ ] ) ; } $ this -> { $ field } -> add ( $ args [ 0 ] ) ; $ this -> completeOwningSide ( $ property , $ args [ 0 ] ) ; return $ this ; }
Adds an object to a collection.

@param string  $field
@param mixed[] $args

@return object

@throws BadMethodCallException
@throws InvalidArgumentException
Adds an object to a collection .