0

When I try to run the query mentioned below, I get this error - strtoupper() expects parameter 1 to be string, array given (/vendor/yiisoft/yii2/db/QueryBuilder.php - Line 1050)

$bookings = \app\models\Bookings::find()
    ->where([
        'AND',
        ['IN', 'member_id', $members_query],
        ['IN', 'resource_id', $resources_query],
        ['>=', 'from_date', $start_date],
        ['<=', 'to_date', $end_date]
    ])->all();

$member_query and $resources_query are ActiveQuery objects. I also tried the variation below but ended up with same error.

$bookings = \app\models\Bookings::find()
    ->where(['IN', 'member_id', $members_query]),
    ->andWhere(['IN', 'resource_id', $resources_query]),
    ->andWhere(['>=', 'from_date', $start_date]),
    ->andWhere(['<=', 'to_date', $end_date])
    ->all();
eth.block
  • 512
  • 1
  • 5
  • 17
  • I don't see anything in your first code that could trigger this error although you don't have to use `IN` like that, you can do `['member_id' => $members_query]` - builder checks if $members_query is array and does `IN` automatically. – Bizley May 23 '17 at 07:50
  • I already tried that but also doesn't work. But if I remove one of the two IN conditions then it starts working. – eth.block May 23 '17 at 07:57
  • Found the issue. It was the `$resources_query`. It had 3 conditions in where clause. Once I added 'AND' clause in it, it started working. Thanks for your help! – eth.block May 23 '17 at 08:05
  • 1
    would you post your $members_query and $resources_query ? – Michael Nguyen May 24 '17 at 04:57

0 Answers0