Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Data Filter not null or empty


Reply

3 Posts   596 Views

Avatar
Raver0124

24 October 2013 at 6:53pm (Last edited: 24 October 2013 6:54pm), Community Member, 8 Posts

Hi guys,

I'm just trying to retrieve a child records where ThumbImage is not null or empty.
Is it possible to do something like this in SilverStripe?

$this->Children()->filter('ThumbImage not null')->sort('created', 'desc')->First();

Thank you

Avatar
Devlin

24 October 2013 at 9:06pm Community Member, 215 Posts

$this->Children()->where('ThumbImage IS NOT NULL')->sort('created', 'desc')->first();

If the ThumbImage is a has_one relation, you have to use 'ThumbImageID' instead:

$this->Children()->where('ThumbImageID IS NOT NULL')->sort('created', 'desc')->first();

Avatar
Raver0124

24 October 2013 at 9:29pm Community Member, 8 Posts

Thank you Devlin,
This is exactly what i was looking for :)