Skip to content

BUG EagerLoadedList throws error when filtering an empty list #11893

@beerbohmdo

Description

@beerbohmdo

Module version(s) affected

5.4, 6.0, 6.1

Description

I think EagerLoadedList should be kind of dropin setting.

But currenly these calls behave different:

$item = Foo::get()->first()?->Relation()->find('Column', 'Value');
$item = Foo::get()->eagerLoad('Relation')->first()?->Relation()->find('Column', 'Value');

The later will throw an error Can't filter by column 'Column' when the Relation is empty.

Because the normaliseFilterArgs calls canFilterBy which will fail if the underlying list is empty.
https://github.com/silverstripe/silverstripe-framework/blob/6/src/ORM/EagerLoadedList.php#L619

The implementation in ArrayList does not throw an error either.

How to reproduce

See above.

Possible Solution

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions