GreenDAO toMany 关系 - 目标实体顺序
GreenDAO toMany Relation - Target Entities Order
我的架构中有一个 toMany 关系 ("A human has 1..N cats")。如果我查询一个实体的 toMany-target 实体,我使用以下代码:
List<Cat> cats = human.getCatList();
返回的列表保证是有序的吗?如果是,取决于哪个 属性?
附加信息(生成代码):
在我的模式(生成器)中,实体创建如下:
Entity human = schema.addEntity("human");
human.addIdProperty().autoincrement();
Entity cat = schema.addEntity("cat");
cat.addIdProperty().autoincrement();
pb = cat.addLongProperty("humanId");
pb.notNull();
pb.indexAsc(null, false);
human.addToMany(cat, pb.getProperty());
因此我认为顺序是由创建的索引(隐含地)定义的,但是查看 CatDao.java
显示索引是在没有定义顺序的情况下创建的:
"CREATE INDEX " + constraint + "IDX_CAT_HUMAN_ID ON CAT (HUMAN_ID);"
将 pb.indexAsc
更改为 pb.indexDesc
会更改索引名称,但不会更改列的索引顺序(请参阅:SQLite Syntax: indexed-column)。
所以 - 这是想要的行为吗?如何定义目标实体的顺序?
Is the returned list guaranteed to be ordered? If yes, dependant on which property?
如果是,则简短回答“是”;长答案没有但是:项目的顺序是隐式未定义的,但可以在 toMany
关系中明确设置。
human.addToMany(cat, [...]).orderAsc([...]);
将在为人类实体创建的 Cat.java
中生成 ORDER BY
语句(参见 Cat#_queryHuman_CatList
)。
I therefore thought the order is (implicitely) defined by the created index, but a look at CatDao.java
showed the index is created without a defined order.
这似乎是想要的行为,因为 SQLite Docs state: Each column name can be followed by one of the "ASC" or "DESC" keywords to indicate sort order. The sort order may or may not be ignored depending on the database file format [...] - given that GreenDAO supports older Android versions (and therefore older SQLite versions, see SO question/answer here) not 在索引上附加排序顺序是有意义的。
我的架构中有一个 toMany 关系 ("A human has 1..N cats")。如果我查询一个实体的 toMany-target 实体,我使用以下代码:
List<Cat> cats = human.getCatList();
返回的列表保证是有序的吗?如果是,取决于哪个 属性?
附加信息(生成代码):
在我的模式(生成器)中,实体创建如下:
Entity human = schema.addEntity("human");
human.addIdProperty().autoincrement();
Entity cat = schema.addEntity("cat");
cat.addIdProperty().autoincrement();
pb = cat.addLongProperty("humanId");
pb.notNull();
pb.indexAsc(null, false);
human.addToMany(cat, pb.getProperty());
因此我认为顺序是由创建的索引(隐含地)定义的,但是查看 CatDao.java
显示索引是在没有定义顺序的情况下创建的:
"CREATE INDEX " + constraint + "IDX_CAT_HUMAN_ID ON CAT (HUMAN_ID);"
将 pb.indexAsc
更改为 pb.indexDesc
会更改索引名称,但不会更改列的索引顺序(请参阅:SQLite Syntax: indexed-column)。
所以 - 这是想要的行为吗?如何定义目标实体的顺序?
Is the returned list guaranteed to be ordered? If yes, dependant on which property?
如果是,则简短回答“是”;长答案没有但是:项目的顺序是隐式未定义的,但可以在 toMany
关系中明确设置。
human.addToMany(cat, [...]).orderAsc([...]);
将在为人类实体创建的 Cat.java
中生成 ORDER BY
语句(参见 Cat#_queryHuman_CatList
)。
I therefore thought the order is (implicitely) defined by the created index, but a look at
CatDao.java
showed the index is created without a defined order.
这似乎是想要的行为,因为 SQLite Docs state: Each column name can be followed by one of the "ASC" or "DESC" keywords to indicate sort order. The sort order may or may not be ignored depending on the database file format [...] - given that GreenDAO supports older Android versions (and therefore older SQLite versions, see SO question/answer here) not 在索引上附加排序顺序是有意义的。