question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How sort by complex field?

See original GitHub issue

Realm 3.7.1

public class Contact extends RealmObject {
    @PrimaryKey
    private long id;
    private String name;
}

If I want to get all contacts and sort by name I use the next method:

RealmResults<Contact> contactRealmResults = realm.where(Contact.class)
                           .findAllSorted("name");

And it’s work fine. OK.

Now the type of field Contact.name is change. The value of filed Contact.name is in TranslatedString.value

public class Company extends RealmObject {
    @PrimaryKey
    private long id;
    private LocalizedString name;
}

public class LocalizedString extends RealmObject {
    private RealmList<TranslatedString> translatedStringList = new RealmList<>();
}

public class TranslatedString extends RealmObject {
    private String locale;
    private String value;
}

So now I need to sort by field TranslatedString.value . And how I can do this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Zhuindencommented, Sep 12, 2017

@cmelchior or make a “composite” primary key by concatenating multiple fields into a single String

public class Contact extends RealmObject {
    @PrimaryKey
    private String idAndLocale; // "" + id + "_" + locale
    @Index
    private long id;
    @Index
    private String locale;
    @Index
    private String name;
}
0reactions
cmelchiorcommented, Sep 18, 2017

@lmdic I assume the above answered your question. If not, feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I sort complex numbers? - Mathematica Stack Exchange
There's no standard way to sort complex numbers. If you re-read your question, it should be obvious what's wrong with it.
Read more >
Performing Complex Sorts - Excel Ribbon Tips
Display the Data tab of the ribbon. · Click the Sort tool. · Use the Sort By drop-down to select the field (or...
Read more >
Sort Complex Numbers VI - NI
Sorts an array of complex numbers in ascending or descending order with respect to real and imaginary parts or magnitude.
Read more >
Sort a list of complex numbers based on how far they are from ...
Code:clcz=input('Enter the array');Y=abs(z);Y=fliplr( sort (Y)) ... Sort a list of complex numbers based on how far they are from the origin.
Read more >
SortbyColumns does not seem to work for a complex data type?
So I wonder if complex data types can be sorted? ... You might re-think if you actually need the complex field type involved...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found