One To Many Relationship documentation insufficient
See original GitHub issueDBFlow Version: 4.2.4
One To Many Relationship documentation insufficient: Missing Ant class in example and explanation on how to save models.
Please add the Ant class to make the One To Many example in the docs complete. It’s essential to get One To Many relationship working.
Since ModelContainers have been dropped, what do we need do in the Ant class instead of associating the former use of the ForeignKeyContainer?
Marco got me on the right track with his post but he ended up overwriting the Queen.save() in which he “associates” Ants with the Queen. Is it by design that you have to set this connection manually before save() or is it a bug?
I ended up with the following Ant class which seems to work. But is this correct?
@Table(database = ColonyDatabase.class)
public class Ant extends BaseModel {
@PrimaryKey(autoincrement = true)
long id;
@Column
String name;
@ForeignKey(stubbedRelationship = true)
Queen queen;
// need to call this for all ants before saving the queen
public void setQueen(Queen q) {
queen = q;
}
}
Thank you very much if you could clarify this.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:10 (3 by maintainers)
Top GitHub Comments
i face the same issue , need help
you can shortcut a
load()
if you want to associate a newqueen
withAnt
by setting thequeen
object, then saving bothAnt
andQueen
.