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.

General Questions

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

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

Bug in removeDuplicates()?


3 Posts   984 Views


3 February 2010 at 5:28am Community Member, 164 Posts

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.


3 February 2010 at 11:41am Community Member, 712 Posts

removeDuplicates() doesn't return anything.


Debug::show($test); // Shows 1 2 1
Debug::show($test); // Shows 1 2


3 February 2010 at 9:05pm Community Member, 164 Posts

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