funteapot15611
funteapot15611

You can find many topics to show 'Using Conditions & Scope not working', such as http://octobercms.com/forum/post/using-conditions-scope-not-working

I modify the code, \cms\modules\backend\widgets\Lists.php From line 432, change to:

            $relationObj = $this->model->{$column->relation}();
            $temp = $relationObj->getRelated()->newQueryWithoutScopes();
            $a = $temp->getQuery()->wheres;
            $b = $relationObj->getQuery()->getQuery()->wheres;
            // delete No.0 condition
            array_splice($b, 0, 1);
            $temp->getQuery()->wheres = array_merge((array) $a, (array) $b);
            $countQuery = $relationObj->getRelationCountQuery($temp, $query);

            $joinSql = $this->isColumnRelated($column, true)
                ? DbDongle::raw("group_concat(" . $sqlSelect . " separator ', ')")
                : DbDongle::raw($sqlSelect);
            $joinSql = $countQuery->select($joinSql)->toSql();

            $wheres = $temp->getQuery()->wheres;
            $search = ' ? ';
            foreach ($wheres as $id => $where) {
                if (isset($where['value']) && (!is_object($where['value']))) {
                    $replace = ' ' . $where['value'] . ' ';
                    $pos = strpos($joinSql, $search);
                    if ($pos !== false) {
                        // Nothing found
                        $joinSql = substr_replace($joinSql, $replace, $pos, strlen($search));
                    }
                }
            }

            $selects[] = Db::raw("(".$joinSql.") as ".$alias);

The reason is $relationObj->getRelationCountQuery did not add the conditions, and the Db::raw did not add the condition value. Because I am not know well the OctoberCMS, maybe it has a better modify.

1-1 of 1