ArrayList's and comparison filters.

80 views
Skip to first unread message

Patrick Nelson

unread,
Jun 15, 2016, 5:54:37 AM6/15/16
to silverst...@googlegroups.com
Am I mistaken or is it really true that array lists do not actually utilize filters? I was racking my brain trying to figure out why the heck this filter wouldn't work at all:

   return $list->filter([
"IntegerField:GreaterThan" => 123,
])->first();

After inspecting the ->filter() method, I noticed this core class didn't seem to handle this in the same way as DataList. It seemed to just do a straight direct comparison... is this an oversight and, if so, should this be added into core?

- Patrick

Sam Minnée

unread,
Jun 15, 2016, 6:12:47 AM6/15/16
to silverst...@googlegroups.com
Hey Patrick,

I'd certainly accept a PR that matches this functionality for ArrayList. The main reason that it hasn't happened is that the current implementation is very dependent on database queries. So it wouldn't be a small piece of work!

As a smaller change, it would probably be worth throwing a more useful error, e.g. "filter not implemented", if you tried to use filters that weren't there. This would also let us start implementing some of the filters, and leaving some of the less critical ones unimplemented. E.g. I don't know if I'd bother with FullTextFilter. This would make is easier to debug issues.

A similar gap probably exists with relationship traversal: I don't think $list->filter(['Relation.Field' => $value]) works. Again, I'd probably start by throwing clearer errors, and then implementing features one by one (I'd expect that a has_one traversal will be easier than a has_many)

--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at https://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/d/optout.
--
Sam Minnée
CEO
SilverStripe Limited

Loz Calver

unread,
Jun 15, 2016, 6:27:24 AM6/15/16
to SilverStripe Core Development
ArrayList has been on my mental list of things to look at (read: list of things I’ve forgotten about) for a while now. I did wonder if we might be able to use a thirdparty library to handle this for us. Something like: http://elliotswebsite.com/Pinq/https://github.com/TimeToogo/Pinq

One of the other issues I wanted to fix (that I remember from an age-old project) was that $list->limit(5)->limit(10) will return 5 results instead of 10 like DataList does. Hopefully the lib I linked would solve that (though I’ve not tested it)

Loz

Ralph Slooten

unread,
Jun 15, 2016, 10:49:10 PM6/15/16
to silverst...@googlegroups.com
This same "issue" has gotten me a few times already (facepalm) so I agree that a user_error would be a good start.

If a third party lib such as the one Loz suggested was implemented, would it be safe to assume that ArrayList would act as a wrapper for that lib, and implement the same filtering syntax as the existing DataList filter()? Obviously certain filtering functionality (such as fulltext) would be missing, in which case I'd suggest a user_error to give the developer a heads-up on that too.

Cheers,
Ralph


--

Christopher Pitt

unread,
Jun 15, 2016, 10:53:26 PM6/15/16
to SilverStripe Core Development
Inb4 DQL

Sam Minnée

unread,
Jun 15, 2016, 11:07:59 PM6/15/16
to silverst...@googlegroups.com
One of the other issues I wanted to fix (that I remember from an age-old project) was that $list->limit(5)->limit(10) will return 5 results instead of 10 like DataList does. Hopefully the lib I linked would solve that (though I’ve not tested it)

I've always thought of this as a bug in DataLIst, not ArrayList, but in any case making them consistent would be good. ;-)

 

Patrick Nelson

unread,
Aug 24, 2016, 11:35:49 PM8/24/16
to silverst...@googlegroups.com
Circling back to this since I noticed this in the DL archives but realized it wasn't officially being tracked yet. Since Loz mentioned he forgot about it, I figured that might be a good idea, so a new issue has been submitted here: https://github.com/silverstripe/silverstripe-framework/issues/5911
Reply all
Reply to author
Forward
0 new messages