S
S
SokolovArtur2016-08-26 13:08:56
Yii
SokolovArtur, 2016-08-26 13:08:56

Question mark? in an ActiveRecord query?

I'm writing a filter for the site. The database is PostgreSQL.
On get parameters I write conditions of selection.

$languageFilter = ActiveRecord::find();

$languageFilter->andWhere('"p"."field_id" = 17');
try {
  $languageFilter->andWhere('"p"."value"::jsonb ?| array' . str_replace('"', "'", (string) Json::encode($filterGetData['language'])));
} catch (InvalidParamException $e) {
  throw new UnprocessableEntityHttpException();
}

$resumeFind->andWhere($languageFilter->where);

As a result, an exception is thrown
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "$1"
LINE 1: AND (("p"."field_id" = 17) AND ("p"."value":: jsonb $1|array['3']))
The string "p"."value"::jsonb ?| array[3] - finds discrepancies between the data that was in the database and the data in the database.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question