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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Data Filter not null or empty


Go to End


3 Posts   6894 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, 344 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 :)