/** Adds a to-many relationship; the target entity is joined to the PK property of this entity (typically the ID). */ public ToMany addToMany(Entity target, Property targetProperty) { Property[] targetProperties = {targetProperty}; return addToMany(null, target, targetProperties); }
/** * Add a to-many relationship; the target entity is joined using the given target property (of the target entity) * and given source property (of this entity). */ public ToMany addToMany(Property sourceProperty, Entity target, Property targetProperty) { Property[] sourceProperties = {sourceProperty}; Property[] targetProperties = {targetProperty}; return addToMany(sourceProperties, target, targetProperties); }
/** * Convenience method for {@link Entity#addToMany(Entity, Property)} with a subsequent call to {@link * ToMany#setName(String)}. */ public ToMany addToMany(Entity target, Property targetProperty, String name) { ToMany toMany = addToMany(target, targetProperty); toMany.setName(name); return toMany; }
protected void createTreeEntity() { Entity treeEntity = schema.addEntity("TreeEntity"); treeEntity.addIdProperty(); Property parentIdProperty = treeEntity.addLongProperty("parentId").getProperty(); treeEntity.addToOne(treeEntity, parentIdProperty).setName("parent"); treeEntity.addToMany(treeEntity, parentIdProperty).setName("children"); }
protected void createToMany() { Entity toManyTargetEntity = schema.addEntity("ToManyTargetEntity"); Property toManyIdProperty = toManyTargetEntity.addLongProperty("toManyId").getProperty(); Property toManyIdDescProperty = toManyTargetEntity.addLongProperty("toManyIdDesc").getProperty(); Property targetIdProperty = toManyTargetEntity.addIdProperty().getProperty(); Property targetJoinProperty = toManyTargetEntity.addStringProperty("targetJoinProperty").getProperty(); Entity toManyEntity = schema.addEntity("ToManyEntity"); Property sourceIdProperty = toManyEntity.addIdProperty().getProperty(); Property sourceJoinProperty = toManyEntity.addStringProperty("sourceJoinProperty").getProperty(); ToMany toMany = toManyEntity.addToMany(toManyTargetEntity, toManyIdProperty); toMany.orderAsc(targetIdProperty); ToMany toManyDesc = toManyEntity.addToMany(toManyTargetEntity, toManyIdDescProperty); toManyDesc.setName("toManyDescList"); toManyDesc.orderDesc(targetIdProperty); ToMany toManyByJoinProperty = toManyEntity .addToMany(sourceJoinProperty, toManyTargetEntity, targetJoinProperty); toManyByJoinProperty.setName("toManyByJoinProperty"); toManyByJoinProperty.orderAsc(targetIdProperty); Property[] sourceProperties = {sourceIdProperty, sourceJoinProperty}; Property[] targetProperties = {toManyIdProperty, targetJoinProperty}; ToMany toManyJoinTwo = toManyEntity.addToMany(sourceProperties, toManyTargetEntity, targetProperties); toManyJoinTwo.setName("toManyJoinTwo"); toManyJoinTwo.orderDesc(targetJoinProperty); toManyJoinTwo.orderDesc(targetIdProperty); Entity toManyJoinEntity = schema.addEntity("JoinManyToDateEntity"); toManyJoinEntity.addIdProperty(); Property id1 = toManyJoinEntity.addLongProperty("idToMany").getProperty(); Property id2 = toManyJoinEntity.addLongProperty("idDate").getProperty(); toManyEntity.addToMany(dateEntity, toManyJoinEntity, id1, id2); }
private Schema createSchema2() { Schema schema2 = new Schema(1, "org.greenrobot.greendao.daotest2"); schema2.setDefaultJavaPackageTest("org.greenrobot.greendao.daotest2.entity"); schema2.setDefaultJavaPackageDao("org.greenrobot.greendao.daotest2.dao"); schema2.enableKeepSectionsByDefault(); Entity keepEntity = schema2.addEntity("KeepEntity"); keepEntity.addIdProperty(); Entity toManyTarget2 = schema2.addEntity("ToManyTarget2"); toManyTarget2.addIdProperty(); Property toManyTarget2FkId = toManyTarget2.addLongProperty("fkId").getProperty(); toManyTarget2.setSkipGenerationTest(true); Entity toOneTarget2 = schema2.addEntity("ToOneTarget2"); toOneTarget2.addIdProperty(); toOneTarget2.setJavaPackage("org.greenrobot.greendao.daotest2.to1_specialentity"); toOneTarget2.setJavaPackageDao("org.greenrobot.greendao.daotest2.to1_specialdao"); toOneTarget2.setJavaPackageTest("org.greenrobot.greendao.daotest2.to1_specialtest"); toOneTarget2.setSkipGenerationTest(true); Entity relationSource2 = schema2.addEntity("RelationSource2"); relationSource2.addIdProperty(); relationSource2.addToMany(toManyTarget2, toManyTarget2FkId); Property toOneId = relationSource2.addLongProperty("toOneId").getProperty(); relationSource2.addToOne(toOneTarget2, toOneId); relationSource2.setJavaPackage("org.greenrobot.greendao.daotest2.specialentity"); relationSource2.setJavaPackageDao("org.greenrobot.greendao.daotest2.specialdao"); relationSource2.setJavaPackageTest("org.greenrobot.greendao.daotest2.specialtest"); relationSource2.setSkipGenerationTest(true); return schema2; }