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

geoff.beaumont
geoff.beaumont

I have a custom plugin which has models with 1:1 relationships to Users (from the Rainlab User plugin). I want to supply administrators with the ability to filter the list of objects by the associated user, so I've set up a filter like so:

user:
    label: User
    modelClass: RainLab\User\Models\User
    nameFrom: name
    scope: filterByUser

The model that I'm filtering has a scope method as follows:

public function scopeFilterByUser($query, $filter)
{
    // This is deliberate - I want to know whether the scope is called
    var_dump($filter);
    die();
    return $query->whereHas('user', function($user) use ($filter) {
        $user->whereIn('id', $filter);
    });
}

The filter appears above the list, I can select users to filter by - but then it always returns the full, unfiltered list. The scope method is never called. It's also worth noting that I have other filters on this list that don't work with relationships, and they work fine.

I've compared compared my code with the (working) group filter in the Rainlab User plugin, and can't see any differences. If I put a similar var_dump/die in the User scope this is hit as expected and the result returned from the AJAX query.

The only other thing that might be pertinent is that there are over 2000 users in the system - however, PHP's max_input_vars has been set to 10000, so this shouldn't be an issue (why does October pass all the unselected options back?!!!). The filter isn't applied when first accessing the page with the filter already held in the session. I've tried linking the filter to a different model that only has around a dozen instances in the database, and that made no difference.

OctoberCMS version is 419, as the environment has to stay on PHP5.6 for now due to another system on the same server.

What could be causing OctoberCMS to not call the scope?

geoff.beaumont
geoff.beaumont

Well, I'm still none the wiser...

On dev, the relation filters started working for no apparent reason (I put some debug code in ListController.php and they started working - reverted the file and they've continued working ever since...). On production, they still don't work.

I've refreshed the entire production system from dev in case there was an out of date file somewhere - it's now definitely identical bar minor differences in the configuration files (database, URL, that sort of thing that's environment specific).

I'm somewhat stumped as to where to look next! Is there a cache somewhere that might need clearing?

1-2 of 2

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