Information Required ?
avatar blueline86
blueline86
25 Oct 2020

Steps to reproduce the issue

Use $query->whereIn() in a frontend model, with an array with more than 1 item.
Sometimes only 1 row is returned.

Expected result

all rows for the array in the where in returned

Actual result

only some rows are returned

System information (as much as possible)

Database Type mysql
Database Version 5.6.49
Database Collation utf8_general_mysql500_ci
Database Connection Collation utf8mb4_general_ci
Database Connection Encryption None
Database Server Supports Connection Encryption No
PHP Version 7.4.11
Web Server Apache
WebServer to PHP Interface litespeed
Joomla! Version Joomla! 4.0.0-beta5-dev Development [ Mañana ] 15-September-2020 19:15 GMT
User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36

Additional comments

$query->whereIn('u.id', $users); - returns only 1 of 4 $users from the array

$query->where('u.id IN(' . implode(',', $db->quote($users)) . ')'); - works as expected and returns all 4 $users in the array

avatar blueline86 blueline86 - open - 25 Oct 2020
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Oct 2020
avatar SharkyKZ
SharkyKZ - comment - 25 Oct 2020

This and related database query methods expect an indexed array ?‍♂️ .

avatar blueline86 blueline86 - change - 25 Oct 2020
The description was changed
avatar blueline86 blueline86 - edited - 25 Oct 2020
avatar Quy Quy - change - 26 Oct 2020
Labels Added: Information Required
avatar Quy Quy - labeled - 26 Oct 2020
avatar sakiss
sakiss - comment - 26 Oct 2020

Check if your $users array uses numerical indexes which are also linearly incremented by 1.
You can call
$users = array_values($users);
before the whereIn

avatar Quy Quy - change - 31 Oct 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-10-31 15:24:28
Closed_By Quy
avatar Quy Quy - close - 31 Oct 2020

Add a Comment

Login with GitHub to post a comment