RushOrm icon indicating copy to clipboard operation
RushOrm copied to clipboard

Lists of children do not retain their order correctly.

Open zean opened this issue 9 years ago • 3 comments

when i save an arraylist item ,the array is resorted and that item is pushed to last, is there a way to go around it?

zean avatar Jul 08 '15 16:07 zean

Hi,

The default load order is the order they are inserted into the database. So there is not a way to resolve this.

This use case has slipped by not sure there is an easy fix for it without making breaking changes.

To get the children in the order you want for now you would have to do another search for them.

This might work although as some are saved at the same time it might still not get the order wrong, in that case you will have to add your own order field and use that.

List<ChildObject> children = new RushSearch()
                .whereChildOf(parent, "childrenFieldName")
                .orderAsc("rush_created")
                .find(ChildObject.class);

I'll leave this open as a bug, but I hope you can work around the issue.

Thanks Stuart

Stuart-campbell avatar Jul 09 '15 08:07 Stuart-campbell

public class Chat_Object extends RushObject {

private String chat_id;
private Chat_User friend;
private Chat_User me;
private int account;
@RushList(classType = Chat_Msg.class)
private List<Chat_Msg> chat_msgs;

}

public class Chat_Msg extends RushObject {

public boolean zapped;
private String chat_id;
private String message_id;
private String text;
private String media_path;
private String thumb_path;
private long timestamp;
private int type;
private boolean read;
private boolean locked;
private boolean show;

}

i currently have this
return new RushSearch() .orderAsc("rush_created") .find(Chat_Object.class);

can you help me make a call where the ChatMsg come sorted by the timestamp? txs

zean avatar Jul 10 '15 14:07 zean

Chat_Object chatObject = // Get your chat object from first search or where ever

List<ChatMsg> orderedMsgs = new RushSearch()
            .whereChildOf(chatObject, "chat_msgs")
            .orderAsc("timestamp")
            .find(ChatMsg.class);

This bug means it will take an extra search as there is no way to have the list on the parent object ordered by default. So you will have to get the list of children directly from a search.

Hopefully this is what your looking for. Thanks

Stuart-campbell avatar Jul 10 '15 14:07 Stuart-campbell