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

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

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

        switch (true) {
            case $property instanceof FieldMetadata && ! $property->isPrimaryKey():
                $this->{$field} = $args[0];
                break;

            case $property instanceof ToOneAssociationMetadata:
                $targetClassName = $property->getTargetEntity();

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

                $this->{$field} = $args[0];
                $this->completeOwningSide($property, $args[0]);
                break;
        }

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

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

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

        switch (true) {
            case $property instanceof FieldMetadata && ! $property->isPrimaryKey():
                $this->{$field} = $args[0];
                break;

            case $property instanceof ToOneAssociationMetadata:
                $targetClassName = $property->getTargetEntity();

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

                $this->{$field} = $args[0];
                $this->completeOwningSide($property, $args[0]);
                break;
        }

        return $this;
    }
private function set ( $ field , $ args ) { $ this -> initializeDoctrine ( ) ; $ property = $ this -> cm -> getProperty ( $ field ) ; if ( ! $ property ) { throw new BadMethodCallException ( "no field with name '" . $ field . "' exists on '" . $ this -> cm -> getClassName ( ) . "'" ) ; } switch ( true ) { case $ property instanceof FieldMetadata && ! $ property -> isPrimaryKey ( ) : $ this -> { $ field } = $ args [ 0 ] ; break ; case $ property instanceof ToOneAssociationMetadata : $ targetClassName = $ property -> getTargetEntity ( ) ; if ( $ args [ 0 ] !== null && ! ( $ args [ 0 ] instanceof $ targetClassName ) ) { throw new InvalidArgumentException ( "Expected persistent object of type '" . $ targetClassName . "'" ) ; } $ this -> { $ field } = $ args [ 0 ] ; $ this -> completeOwningSide ( $ property , $ args [ 0 ] ) ; break ; } return $ this ; }
Sets a persistent fields value.

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

@return object

@throws BadMethodCallException   When no persistent field exists by that name.
@throws InvalidArgumentException When the wrong target object type is passed to an association.
Sets a persistent fields value .