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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1924 Views

Avatar
etkinss

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;

$cities->removeDuplicates('Sehir');

return $cities;
}

Attached Files
Avatar
martimiz

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: http://www.silverstripe.org/data-model-questions/show/22128

Avatar
Bambii7

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.