Jump to:

22977 Posts in 11747 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Bug in removeDuplicates()?

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

Page: 1
Go to End
Author Topic: 912 Views
  • MarijnKampf
    Avatar
    Community Member
    161 Posts

    Bug in removeDuplicates()? Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Bug in removeDuplicates()? Link to this post

    removeDuplicates() doesn't return anything.

    try:

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

  • MarijnKampf
    Avatar
    Community Member
    161 Posts

    Re: Bug in removeDuplicates()? Link to this post

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

    912 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.