2015-05-25 23 views
5

Bazı hesapları ayda aylamak istiyorum, bunu Realm.io ile yapabilir miyim?Realm.io GroupBy ile Sorgu

public class Account extends RealmObject { 
..... 
private Date date; 
} 

RealmResults accounts = realm.where(Account.class) 
.beginGroup() 
.equalTo("date", "MONTH(date)")//<----- wrong code 
.endGroup() 
.findAll(); 

sayesinde

cevap

2

Diyar GroupBy henüz desteklememektedir. Ayrıca beginGroup() öğesinin aslında parantez ile aynı olduğunu unutmayın. Ayda

değiştiğinde

// Between is [ monthStart, monthEnd ] 
Date monthStart = new GregorianCalendar(2015, 5, 1).getTime(); 
Date monthEnd = new GregorianCalendar(2015, 6, 1).getTime() - 1; 
accounts = realm.where(Account.class).between("date", monthStart, monthEnd).findAll(); 

veya böyle bir şey algılamak için:

Realm
// SQL pseudo code 
SELECT * FROM Account WHERE (date = MONTH(date)) 

tek ay seçmek için böyle bir şey yapmak gerekir: Yani sorgu aslında olarak yorumlanır Hızlı yanıtınız için çok teşekkür ederim.

// pseudo code. You might want to use Calendar instead 
accounts = realm.where(Account.class).findAllSorted("date") 
Iterator<Account> it = accounts.iterator(); 
int previousMonth = it.next().getDate().getMonth(); 
while (it.hasNext) { 
    int month = it.next().getDate().getMonth(); 
    if (month != previousMonth) { 
    // month changed 
    } 
    previousMonth = month; 
} 
+0

İlk önce benim için çalışıyor. – schwertfisch