Gets the SQL statement used for deleting a row from the collection.

@param \Doctrine\ORM\PersistentCollection $collection

@return string[]|string[][] ordered tuple containing the SQL to be executed and an array
of types for bound parameters
4008
protected function getDeleteRowSQL(PersistentCollection $collection)
    {
        $mapping     = $collection->getMapping();
        $class       = $this->em->getClassMetadata($mapping['sourceEntity']);
        $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
        $columns     = array();
        $types       = array();

        foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em);
        }

        foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em);
        }

        return array(
            'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform)
            . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?',
            $types,
        );
    }
1058270
private function createReferenceManyWithRepositoryMethodIterator(PersistentCollectionInterface $collection)
    {
        $mapping          = $collection->getMapping();
        $repositoryMethod = $mapping->repositoryMethod;
        $repository       = $this->dm->getRepository($mapping->targetDocument);
        $iterator         = $repository->$repositoryMethod($collection->getOwner());

        if (!$iterator instanceof Iterator) {
            throw new \BadMethodCallException(sprintf('Expected repository method %s to return an iterable object', $repositoryMethod));
        }

        if (!empty($mapping->prime)) {
            $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork());
            $primers         = array_combine($mapping->prime, array_fill(0, count($mapping->prime), true));
            $class           = $this->dm->getClassMetadata($mapping['targetDocument']);

            $iterator = new PrimingIterator(
                $iterator,
                $class,
                $referencePrimer,
                $primers,
                $collection->isReadOnly()
            );
        }

        return $iterator;
    }
1003271
private function getIds(
        $collection = null,
        $systemCollections = true,
        $types = null,
        $search = null,
        $orderBy = null,
        $orderSort = null,
        $limit = null,
        $offset = null
    ) {
        $subQuery = $this->getIdsQuery(
            $collection,
            $systemCollections,
            $types,
            $search,
            $orderBy,
            $orderSort,
            $limit,
            $offset
        );

        return $subQuery->getScalarResult();
    }
1209370
public function getKeys($collection)
    {
        $cursor = $this->server->executeQuery($this->database . '.' . $collection,
            new \MongoDb\Driver\Query([], ['limit' => 1]));

        $result = current($cursor->toArray());

        $this->queriesResultCache[ 'collectionKeys' ][ $collection ] = [];

        foreach (get_object_vars($result) as $key => $value) {
            $this->queriesResultCache[ 'collectionKeys' ][ $collection ][] = $key;
        }

        return $this->queriesResultCache[ 'collectionKeys' ][ $collection ];
    }
696656
protected static function getClassFromCollection( array $collection )
    {
        // Make sure everything in this container is of __exactly__ the same type.
        // This is a stronger check than the entity container performs (child entities are ok in the container)
        $classes = array_unique( array_map( 'get_class', $collection ) );

        if( count( $classes ) > 1 ) {
            // TODO this could fallback to persisting every entity individually. That would work.
            throw new \Exception(
                sprintf(
                    "Can't manage entities in a container with multiple types, these are %s.",
                    implode( ", ", $classes )
                )
            );
        }
        return array_pop( $classes );

    }
1058133
public function selectCollection($db, $collection)
    {
        $this->initialize();
        return $this->selectDatabase($db)->selectCollection($collection);
    }
13072
private function model($collection)
    {
        return $this->model->setConnection($this->connection)->setTable($collection)->useWritePdo();
    }
361640
public function loadCollectionItemsData(Collection $collection): array
    {
        $query = $this->getItemSelectQuery();
        $query->where(
            $query->expr()->eq('collection_id', ':collection_id')
        )
        ->setParameter('collection_id', $collection->id, Type::INTEGER);

        $this->applyStatusCondition($query, $collection->status);

        $query->addOrderBy('position', 'ASC');

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
1347327
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
    {
        $query     = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
        $documents = $query->execute()->toArray();

        foreach ($documents as $key => $document) {
            $collection->add($document);
        }
    }
167774
public function queriedDelete(Query $query)
    {
        if ($query->getLimit()
            || $query->getSort()
            || ($query instanceof RqlQuery && $query->getGroupBy())
            || $query->getSelect()) {
            throw new InvalidArgumentException('Only where clause allowed for delete');
        }

        $conditionBuilder = new SqlConditionBuilder(
            $this->getDbTable()->getAdapter(),
            $this->getDbTable()->getTable()
        );

        $sql = new Sql($this->getDbTable()->getAdapter());
        $delete = $sql->delete($this->getDbTable()->getTable());
        $delete->where($conditionBuilder->__invoke($query->getQuery()));
        $sqlString = $sql->buildSqlString($delete);

        $adapter = $this->dbTable->getAdapter();
        $shouldDeletedIds = array_map(function ($item) {
            return $item[$this->getIdentifier()];
        }, $this->query($query));

        try {
            $statement = $adapter->getDriver()->createStatement($sqlString);
            $result = $statement->execute();
        } catch (\Throwable $e) {
            throw new DataStoreException("Can't delete records using query", 0, $e);
        }

        if (count($shouldDeletedIds) === $result->getAffectedRows()) {
            return $shouldDeletedIds;
        } else {
            $result = $this->query($query);

            foreach ($result as $record) {
                if (in_array($record[$this->getIdentifier()], $shouldDeletedIds)) {
                    unset($shouldDeletedIds[$record[$this->getIdentifier()]]);
                }
            }
        }

        return $shouldDeletedIds;
    }
1152646
public function getTree(\Illuminate\Database\Eloquent\Collection $collection)
    {
        $collection = $collection->sortBy($this->repository->getParentField())
            ->sortBy($this->repository->getOrderField());

        return $this->getChildren(
            $collection,
            $this->repository->getRootParentId()
        );
    }
94985
public function schemaCollection(SchemaCollection $collection = null)
    {
        deprecationWarning(
            'Connection::schemaCollection() is deprecated. ' .
            'Use Connection::setSchemaCollection()/getSchemaCollection() instead.'
        );
        if ($collection !== null) {
            $this->setSchemaCollection($collection);
        }

        return $this->getSchemaCollection();
    }
1068209
public function get_one($collection = "")
	{
		if (empty($collection))
		{
			throw new \Mongo_DbException("In order to retrieve documents from MongoDB you must provide a collection name.");
		}

		if ($this->profiling)
		{
			$query = json_encode(array(
			'type'			=> 'findOne',
			'collection'	=> $collection,
			'select'		=> $this->selects,
			'where'			=> $this->wheres,
			));

			$benchmark = \Profiler::start((string) $this->db, $query);
		}

		$returns = $this->db->{$collection}->findOne($this->wheres, $this->selects);

		if (isset($benchmark))
		{
			\Profiler::stop($benchmark);
		}

		$this->_clear();

		return $returns;
	}
920680
public function deleteRegistrationsOnCollection(\collection $collection)
    {
        $qb = $this->repository->createQueryBuilder('d');
        $qb->delete('Phraseanet:Registration', 'd');
        $qb->where($qb->expr()->eq('d.baseId', ':base'));
        $qb->setParameter(':base', $collection->get_base_id());
        $qb->getQuery()->execute();
    }
1139398
protected function activeLogs(Collection $collection)
    {
        $return = [];
        foreach ($collection as $model) {
            $module = $model->component->name;
            if (!isset($return[$module][$model->name])) {
                $return[$module][$model->name] = 0;
            }
            $return[$module][$model->name] += 1;
        }
        return $return;
    }
431680
protected function getFreshDistinct($wheres)
    {
        $column = isset($this->columns[0]) ? $this->columns[0] : '_id';

        // Execute distinct
        if ($wheres) {
            $result = $this->collection->distinct($column, $wheres);
        } else {
            $result = $this->collection->distinct($column);
        }

        return $result;
    }
1217054
public function asc(array $collection)
    {
        $count = count($collection);

        if ($count < 2) {
            return $collection;
        }

        $leftCollection = array();
        $rightCollection = array();

        reset($collection);

        $sortPivot = key($collection);
        $pivot = array_shift($collection);

        foreach ($collection as $key => $value) {
            if ($value < $pivot == $this->forwardSort) {
                $leftCollection[$key] = $value;
            } else {
                $rightCollection[$key] = $value;
            }
        }

        return array_merge($this->asc($leftCollection),
            array($sortPivot => $pivot),
            $this->asc($rightCollection));
    }