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

Excluding data from a dataobjectset


Reply

3 Posts   854 Views

Avatar
pingu

28 November 2010 at 2:56am Community Member, 75 Posts

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

Avatar
swaiba

28 November 2010 at 8:05am Forum Moderator, 1796 Posts

remove does work, but how about...

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

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

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

Avatar
pingu

28 November 2010 at 8:48pm Community Member, 75 Posts

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.