public function add(CompositableInterface $entity): DocumentCompositor
    {
        //Detaching entity
        $entity = clone $entity;

        $this->assertSupported($entity);

        if (!$this->has($entity)) {
            $this->entities[] = $entity;
        }

        $this->atomics['$addToSet'][] = $entity;

        return $this;
    }
public function add(CompositableInterface $entity): DocumentCompositor
    {
        //Detaching entity
        $entity = clone $entity;

        $this->assertSupported($entity);

        if (!$this->has($entity)) {
            $this->entities[] = $entity;
        }

        $this->atomics['$addToSet'][] = $entity;

        return $this;
    }
public function add ( CompositableInterface $ entity ) : DocumentCompositor { //Detaching entity $ entity = clone $ entity ; $ this -> assertSupported ( $ entity ) ; if ( ! $ this -> has ( $ entity ) ) { $ this -> entities [ ] = $ entity ; } $ this -> atomics [ '$addToSet' ] [ ] = $ entity ; return $ this ; }
Add entity to set, only one instance of document must be presented.

Be aware that any added entity will be cloned in order to detach it from passed object:
$user->addresses->add($address);
$address->city = 'Minsk'; //this will have no effect of $user->addresses

@param CompositableInterface $entity

@return DocumentCompositor

@throws CompositorException When entity is invalid type.
Add entity to set only one instance of document must be presented .