Skip to content

Can't set subquery as WHERE condition. #1775

Description

@nowackipawel
(new \ExampleModel)->where('(SELECT COUNT(*) FROM t1 WHERE t1_exa_id = ex_id)',10);

The reason is in whereHaving() method:

				$op = $this->getOperator($k);
				$k  = trim(str_replace($op, '', $k)); //here...

I am wondering if we could introduce method which allows us to turn off filtering operators from "field" names.

I think the solution will be:

  1. changing whereHavingMethod():

				$op = $this->getOperator($k);
				if($escapeField)
				{
					$k  = trim(str_replace($op, '', $k));
				}
  1. changing all whereX() methods like this:
	public function where($key, $value = null, $escape = null, $escapeField = true)
	{
		return $this->whereHaving('QBWhere', $key, $value, 'AND ', $escape, $escapeField);
	}

or intruduce new method like escapeFields(bool $escape = true)


	/**
	 * If operators are existed in names of fields should be deleted or not.
	 *
	 * @var bool
	 */
	protected $escapeFields = true;

	/**
	 * Allows to turn off deleting operators from field names.
	 * @param bool $escape
	 * @return $this
	 */
	public function setEscapeFields(bool $escape = true)
	{
		$this->escapeFields = $escape;
		return $this;
	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions