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   765 Views

Avatar
Raver0124

Community Member, 8 Posts

24 October 2013 at 6:53pm

Edited: 24/10/2013 6:54pm

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

Community Member, 217 Posts

24 October 2013 at 9:06pm

$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

Community Member, 8 Posts

24 October 2013 at 9:29pm

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