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

DataObject distinct problem


Reply

3 Posts   621 Views

Avatar
etkinss

8 May 2013 at 9:50pm Community Member, 2 Posts

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
Avatar
martimiz

9 May 2013 at 12:09am Forum Moderator, 1091 Posts

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

Avatar
Bambii7

9 May 2013 at 4:27pm Community Member, 254 Posts

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.