This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

danderson66694
danderson66694

I'm working on a backend form with a tab that will display the categories associated with another model, however I would like to display just the leaf categories in the partial list... I'm having a rough time making this work.

Everything seems to be working correctly as far as the relationship & partial goes, but I am trying to filter the categories by providing a scope to my hasMany model:

model/Account.php:

    public $hasMany = [
        'categories' => [
            '*\*\Models\Category',
            'order' => 'label',
            'key' => 'account_id',
            'scope' => [Category::class, 'scopeOnlyLeaves']
        ]
    ];

model/Category.php:

    public static function scopeOnlyLeaves($query)
    {
        return $query->leaves();
    }

Seems like this should work, but it throws the following error: "Illegal operator and value combination"

Here is a slice of the stack:

#0 {main}  
[2022-05-18 17:14:18] local.ERROR: InvalidArgumentException: Illegal operator and value combination. in *\resort\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:743
Stack trace:
#0 *\resort\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(649): Illuminate\Database\Query\Builder->prepareValueAndOperator(NULL, '>=', false)
#1 *\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(241): Illuminate\Database\Query\Builder->where('nest_left', '>=', NULL)
#2 *\vendor\october\rain\src\Database\Traits\NestedTree.php(421): Illuminate\Database\Eloquent\Builder->where('nest_left', '>=', NULL)

It appears the 'nest_left' column has a NULL value, but looking at the database every one of those entries does have a value for that column.

Does anybody have any tips for me? I'm feeling a bit lost here.

EDIT: I did try a function name other than 'scopeOnlyLeaves' in case that was causing some unexpected issues

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.