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, Ed, biapar, Willr, Ingo, swaiba

DataObject distinct problem

Go to End

3 Posts   1500 Views


Community Member, 2 Posts

8 May 2013 at 9:50pm

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;


return $cities;

Attached Files

Forum Moderator, 1391 Posts

9 May 2013 at 12:09am

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:


Community Member, 254 Posts

9 May 2013 at 4:27pm

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.