Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » DataObject distinct problem

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: 605 Views
  • etkinss
    Avatar
    Community Member
    2 Posts

    DataObject distinct problem Link to this post

    i need to get the distinct Ilans. I've tried using removeDuplicates but it didn't remove duplicates from the drop down menu.

    function getUniqueCities() {

    $cities = DataObject::get('Ilan', '', 'Sehir ASC');
    if(!$cities) return false;

    $cities->removeDuplicates('Sehir');

    return $cities;
    }

    Attached Files
  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: DataObject distinct problem Link to this post

    That would probably be because the query returns entire records, where at least the ID is never duplicated. Maybe only select the city column would work for you?

    As here: http://www.silverstripe.org/data-model-questions/show/22128

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: DataObject distinct problem Link to this post

    Are you using 2.4 or 3?? Looks like in SS3 this is only available on an ArrayList not a DataList...

    If SS3 you could try
    $cities = DataObject::get('Ilan', null, 'Sehir ASC', null, null, 'ArrayList');

    It would be best to push all this back into a DB query if possible, with something like GROUP BY Sheir. Other wise it's just loading unnecessary stuff into memory + SQL will be much fast at sorting out the duplicates.

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