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.

Data Model Questions /

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

Getting DataObjects with NULL values


Go to End


3 Posts   2704 Views

Avatar
NicolasLeuenberger

Community Member, 11 Posts

20 January 2012 at 11:00pm

Hi dear community

One of my models is an event (AgendaEintrag) with a DateField. If no date is set, the MySQL-Entry contains the value NULL. Now I'd like to display all Events without a date. This does not work:

$agendaEintraege = DataObject::get("AgendaEintrag", "Date=NULL", "Date ASC");

If I search for anything else, it works. I can for example display past events:

$agendaEintraege = DataObject::get("AgendaEintrag", "Date=<CURDATE()", "Date ASC");

Any idea how I can get those NULL containing entries? Thanks :-)

Avatar
swaiba

Forum Moderator, 1899 Posts

20 January 2012 at 11:06pm

how about "Date IS NULL" I think that is how MYSQL does it

Avatar
NicolasLeuenberger

Community Member, 11 Posts

20 January 2012 at 11:08pm

Jackpot!

Wow, that was fast and the perfect answer. Thanks so much :-)