Sagarmichael
Sagarmichael

Reputation: 1624

Grails 3 collections to one then sort

I am not sure if this can be done,

I have 3 collections all with a current date tag. I am wanting to sort all the collections by date and give back only one collections.

my collections are Picture, Text and Video. I can pull out each collection and sort by date on its own but i would like to merge them all and then sort by date. Is this possible. Currently I am using a separate domain that keep the order of the collections and pulls out each object one by one in order, but this seems a bad way of doing it.

Can this be done?

Upvotes: 1

Views: 76

Answers (1)

Mr. Cat
Mr. Cat

Reputation: 3552

if I've understood you right, you can try to use sort() method. def sortedCommon = (textCollection + videoCollection + pictureCollection).sort{it.date}

Or as Miguel Prz said: "build an inherit schema: Text, Video and Picture inherits from Item, and work at this level". It's a good suggestion.

Upvotes: 1

Related Questions