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.

Data Model Questions /

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

Excluding data from a dataobjectset

Go to End

3 Posts   1202 Views


Community Member, 75 Posts

28 November 2010 at 2:56am

Is there a way to exclude a result from a dataobjectset without affecting it in the database?
I've tried remove() but this writes to the database.

My scenario is as follows:
- I have a list of articles
- One of those articles flagged as "featured" will be a featured article, this will be selected at random from all articles marked as featured
- I need to get the dataobjectset of the rest of the articles, excluding the featured one


Forum Moderator, 1899 Posts

28 November 2010 at 8:05am

remove does work, but how about...

$newresult = new DataObjectSet();
foreach ($result as $do) {
if (!$do->Featured)

or in the template
<% control result %>
<% if Featured != true %>
<% end_if %>
<% end_control %>

or even better use the where clause of the DataOBject::get()


Community Member, 75 Posts

28 November 2010 at 8:48pm

Thanks swaiba, I ended up using where after I posted. I was trying to avoid code repetition, but in this instance it was the most efficient way to do it.