Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Data Filter not null or empty

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

Page: 1
Go to End
Author Topic: 498 Views
  • Raver0124
    Avatar
    Community Member
    8 Posts

    Data Filter not null or empty Link to this post

    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

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Data Filter not null or empty Link to this post

    $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();

  • Raver0124
    Avatar
    Community Member
    8 Posts

    Re: Data Filter not null or empty Link to this post

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

    498 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.