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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Bug in removeDuplicates()?


Go to End


3 Posts   1408 Views

Avatar
MarijnKampf

Community Member, 176 Posts

3 February 2010 at 5:28am

I'm combining two DataObjectSets and I want only the unique entries.

I thought it was an error in my code, but it appears to me that removeDuplicates() actually removes all entries. I'm not quite sure whether it's a bug as I may have something else wrong in the code. I've written a quick test script, can someone please verify whether this is a bug or an error on my side?

		$one = new DataObject();
		$one->ID = 1;
		$one->Title = "One";
		$two = new DataObject();
		$two->ID = 2;
		$two->Title = "Two";

		$test = new DataObjectSet();
		$test->addWithoutWrite ($one);
		$test->addWithoutWrite ($two);
		$test->addWithoutWrite ($one);

		Debug::show($test); // Shows 1 2 1
		Debug::show($test->removeDuplicates()); // Empty.

Avatar
Hamish

Community Member, 712 Posts

3 February 2010 at 11:41am

removeDuplicates() doesn't return anything.

try:

...
Debug::show($test); // Shows 1 2 1 
$test->removeDuplicates();
Debug::show($test); // Shows 1 2

Avatar
MarijnKampf

Community Member, 176 Posts

3 February 2010 at 9:05pm

Thank you Hamish, should have read the docs better. Clearly another case of user error :)