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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

How to remove duplicated entries from displaying?


Go to End


3 Posts   1900 Views

Avatar
Digital Punk

Community Member, 51 Posts

6 January 2010 at 1:27am

Hi there,

I have many-many DOM where Logos are related to NewsPages. I would like to get a NewsPages where LogoID is unique (would like to show only one newspage where is the same LogoID). How could I use array_unique with this dataobject set?:

function GetNewsByLogos() {
	  $doSet = DataObject::get(
		$callerClass = "NewsPage",
		$filter = "`SiteTree`.ParentID = 111 AND `NewsPage`.LogoID != '' ",
		$sort = "",
		$join = "",
		$limit = ""
	  );
	  return $doSet ? $doSet : false;
	}

Thanks for any help!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

6 January 2010 at 2:20am

function GetNewsByLogos() {
if($set = DataObject::get("NewsPage", "ParentID = 111 AND `NewsPage`.LogoID != '' "))
return $set->removeDuplicates();
return false; 
}

Avatar
Digital Punk

Community Member, 51 Posts

6 January 2010 at 3:35am

Edited: 08/01/2010 12:00am

To: UncleCheese

I tried your code, but it's bringing me no entries after "removeDuplicates".

Before "removeDuplicates" I successfully got 3 news entries:

id1 entry1 logoID=1
id2 entry2 logoID=1
id3 entry3 logoID=2

In example above entry2 has the same logo (logoID=1) and needed to be removed from the displaying on the page. Any ideas how to get this?

I appreciate your help.

Best regards
Mindaugas