/** * Checks whether the given managed entity exists in the database. * * @param object $entity * @return bool */ public function exists($entity) { $metadata = $this->getMetadata($entity); $identifier = $metadata->getIdentifier(true); if (empty($identifier)) { return false; } return (bool) $this->connection->fetchColumn('SELECT 1 FROM ' . $metadata->getTable() . ' WHERE ' . $identifier . '=' . $this->connection->quote($metadata->getValue($entity, $identifier, true))); }
/** * Creates and adds a "where FIND_IN_SET" equivalent to the query. * * @param string $column * @param mixed $values * @param bool $not * @param string $type * @return self */ public function whereInSet($column, $values, $not = false, $type = null) { $not = $not ? ' NOT' : ''; $values = (array) $values; if (count($values) === 1 && $this->connection->getDatabasePlatform() instanceof MySqlPlatform) { $value = $this->connection->quote(current($values)); return $this->addWhere("{$not} FIND_IN_SET({$value}, {$column})", [], $type); } $values = implode('|', (array) $values); return $this->addWhere("{$column}{$not} REGEXP " . $this->connection->quote("(^|,)({$values})(\$|,)"), [], $type); }