My Show object looks like this:
class Show: RLMObject {
dynamic var venue: Venue?
}
and my Venue object:
class Venue: RLMObject {
dynamic var title = ""
}
I need to be able to sort my Show objects by their Venue object's titles. I tried the following but got an error:
allShowsByLocation = Show.allObjects().sortedResultsUsingProperty("venue.title", ascending: true)
The error is: Invalid sort column', reason: 'Column named '(null)' not found.
Realm doesn't yet support sorting RLMResults
by a sub-property. As a work-around, you could query for Venue
s and return its linking object for each index:
allVenues = Venue.allObjects().sortedResultsUsingProperty("title", ascending: true)
func showAtIndex(index: UInt) -> Show {
return (allVenues[index] as Venue).linkingObjectsOfClass("Show", forProperty: "venue")
}
Or you could simply add a venueTitle
property to your Show
model which would then allow your query to work:
allShowsByLocation = Show.allObjects().sortedResultsUsingProperty("venueTitle", ascending: true)
You can also subscribe to GitHub issue #1199 to follow our progress on supporting sub-property sorting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With