Doctrine missing “WHERE” clause

I’m attempting to move my Behat tests from Jenkins (which builds a server each run), to Docker, so that I can add it to Travis.

I’ve run in to a little problem where the WHERE part of a query isn’t being inserted by Doctrine. The DQL output is this:

  • How to deploy mongoDB Docker image to Elastic Beanstalk?
  • how to connect to localhost:9092 from docker container using docker-compose and not using docker bridge
  • How to specify IP of docker container in Marathon?
  • Error while execing a docker image
  • Can't make Docker with Python run in windows
  • Installing Gitlab CI using Docker for the Ci and the Runners, and make it persistent after reboot
  • SELECT v FROM \Database\Entity\SoftwareVersion v WHERE  ORDER BY v.versionMajor DESC, v.versionMinor DESC, v.versionPatch DESC, v.createdAt DESC

    As you can see, nothing between WHERE and ORDER.

    The query builder code looks like this:

     * Get the criteria array for versions
     * @param SoftwareProduct $product Required. The product to check versions for
     * @param SoftwareOperatingSystem $operatingSystem Required. The operating system you are using.
     * @param string $version Optional. Approximate or exact version to check for. Eg 2.0 Might return 2.0.2
     * @param string $order Should be ASC or DESC. Default: DESC
     * @param int|null $limit How many results you want. Leave blank for all
     * @return SoftwareVersion[]
     * @throws Exception
    public function getVersions(
        SoftwareProduct $product,
        SoftwareOperatingSystem $operatingSystem = null,
        $version = null,
        $order = 'DESC',
        $limit = null
    ) {
        if ($order != 'DESC' && $order != 'ASC') {
            throw new \DomainException("Invalid order '$order'");
        $builder = $this->getEntityManager()
            ->from('\Database\Entity\SoftwareVersion', 'v')
            ->andWhere('v.deletedAt IS NULL')
            ->andWhere($builder->expr()->lt('v.releaseDate', ':releaseDate'))
            ->setParameter('releaseDate', date('Y-m-d H:i:s'))
            ->andWhere($builder->expr()->eq('v.product', ':product'))
            ->setParameter('product', $product->getId())
        // Anonymous function for simplified code
        $equalIfExists = function ($key, $value) use ($builder) {
            if ($value !== null) {
                    ->andWhere($builder->expr()->eq("v.$key", ":$key"))
                    ->setParameter($key, $value);
        // OS
        $equalIfExists('operatingSystem', $operatingSystem);
        // Version Number
        $versionObject = $this->stringToVersion($version);
        $equalIfExists('versionMajor', $versionObject->getVersionMajor());
        $equalIfExists('versionMinor', $versionObject->getVersionMinor());
        $equalIfExists('versionPatch', $versionObject->getVersionPatch());
        // Version Meta
            ->andWhere($builder->expr()->like("v.meta", ":meta"))
            ->setParameter('meta', $versionObject->getMeta() ? "{$versionObject->getMeta()}%" : '');
            ->addOrderBy('v.versionMajor', $order)
            ->addOrderBy('v.versionMinor', $order)
            ->addOrderBy('v.versionPatch', $order)
            ->addOrderBy('v.createdAt', $order);
        $query = $builder->getQuery();
        if ($limit) {
        return $query->execute();

    I know, it looks pretty complicated, but even if we take the first few lines:

        ->from('\Mischief\Database\Entity\SoftwareVersion', 'v')
        ->andWhere('v.deletedAt IS NULL')

    It still doesn’t work.

    What’s more interesting: this code is live and functions as expected. I’ve checked the project dependencies are the same.

    The docker file for my PHP container is this:

    FROM php:7-fpm
    RUN docker-php-ext-install pdo pdo_mysql mbstring

    I can’t see any modules on live that aren’t in here.

    So where is my WHERE? 🙂

    Please ask if I can offer any more information.

  • How to completely destroy docker container from marathon UI?
  • Maven's Lifecycle in Dockerfile
  • Docker: php7.0-fpm Executable file not found in $PATH
  • kairosdb service not starting in container
  • Run postgresql docker image with persistent data returns permission error
  • Issue in Azure Cloud when InetAddress.getLocalHost is called
  • One Solution collect form web for “Doctrine missing “WHERE” clause”

        ->from('\Database\Entity\SoftwareVersion', 'v')
        ->where('v.deletedAt IS NULL')
        ->andwhere($builder->expr()->lt('v.releaseDate', ':releaseDate'))
        ->andwhere($builder->expr()->eq('v.product', ':product'))
        ->setParameter('releaseDate', date('Y-m-d H:i:s'))
        ->setParameter('product', $product->getId())
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.