public function includesReferenceTo(object $document) : self
    {
        $this->requiresCurrentField();
        $mapping   = $this->getReferenceMapping();
        $reference = $this->dm->createReference($document, $mapping);
        $storeAs   = $mapping['storeAs'] ?? null;
        $keys      = [];

        switch ($storeAs) {
            case ClassMetadata::REFERENCE_STORE_AS_ID:
                $this->query[$mapping['name']] = $reference;
                return $this;
                break;

            case ClassMetadata::REFERENCE_STORE_AS_REF:
                $keys = ['id' => true];
                break;

            case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
            case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
                $keys = ['$ref' => true, '$id' => true, '$db' => true];

                if ($storeAs === ClassMetadata::REFERENCE_STORE_AS_DB_REF) {
                    unset($keys['$db']);
                }

                if (isset($mapping['targetDocument'])) {
                    unset($keys['$ref'], $keys['$db']);
                }
                break;

            default:
                throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
        }

        foreach ($keys as $key => $value) {
            $this->query[$mapping['name']]['$elemMatch'][$key] = $reference[$key];
        }

        return $this;
    }
public function includesReferenceTo(object $document) : self
    {
        $this->requiresCurrentField();
        $mapping   = $this->getReferenceMapping();
        $reference = $this->dm->createReference($document, $mapping);
        $storeAs   = $mapping['storeAs'] ?? null;
        $keys      = [];

        switch ($storeAs) {
            case ClassMetadata::REFERENCE_STORE_AS_ID:
                $this->query[$mapping['name']] = $reference;
                return $this;
                break;

            case ClassMetadata::REFERENCE_STORE_AS_REF:
                $keys = ['id' => true];
                break;

            case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
            case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
                $keys = ['$ref' => true, '$id' => true, '$db' => true];

                if ($storeAs === ClassMetadata::REFERENCE_STORE_AS_DB_REF) {
                    unset($keys['$db']);
                }

                if (isset($mapping['targetDocument'])) {
                    unset($keys['$ref'], $keys['$db']);
                }
                break;

            default:
                throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
        }

        foreach ($keys as $key => $value) {
            $this->query[$mapping['name']]['$elemMatch'][$key] = $reference[$key];
        }

        return $this;
    }
public function includesReferenceTo ( object $ document ) : self { $ this -> requiresCurrentField ( ) ; $ mapping = $ this -> getReferenceMapping ( ) ; $ reference = $ this -> dm -> createReference ( $ document , $ mapping ) ; $ storeAs = $ mapping [ 'storeAs' ] ?? null ; $ keys = [ ] ; switch ( $ storeAs ) { case ClassMetadata :: REFERENCE_STORE_AS_ID : $ this -> query [ $ mapping [ 'name' ] ] = $ reference ; return $ this ; break ; case ClassMetadata :: REFERENCE_STORE_AS_REF : $ keys = [ 'id' => true ] ; break ; case ClassMetadata :: REFERENCE_STORE_AS_DB_REF : case ClassMetadata :: REFERENCE_STORE_AS_DB_REF_WITH_DB : $ keys = [ '$ref' => true , '$id' => true , '$db' => true ] ; if ( $ storeAs === ClassMetadata :: REFERENCE_STORE_AS_DB_REF ) { unset ( $ keys [ '$db' ] ) ; } if ( isset ( $ mapping [ 'targetDocument' ] ) ) { unset ( $ keys [ '$ref' ] , $ keys [ '$db' ] ) ; } break ; default : throw new InvalidArgumentException ( sprintf ( 'Reference type %s is invalid.' , $ storeAs ) ) ; } foreach ( $ keys as $ key => $ value ) { $ this -> query [ $ mapping [ 'name' ] ] [ '$elemMatch' ] [ $ key ] = $ reference [ $ key ] ; } return $ this ; }
Checks that the current field includes a reference to the supplied document.
Checks that the current field includes a reference to the supplied document .