Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to remove duplicated entries from displaying?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1131 Views
  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    How to remove duplicated entries from displaying? Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: How to remove duplicated entries from displaying? Link to this post

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

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: How to remove duplicated entries from displaying? Link to this post

    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

    1131 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.