为什么在 flutter 中使用“ObjectBox”将相同的子项添加到第二个父项时,第一个父项模型引用被设置为 null?
我有两个对象,一个父模型具有 ToOne
关系,另一个子模型与父模型具有 ToMany
关系。现在,如果我有两个父母正在设置与孩子的关系,那么当设置第二个父母引用时,第一个父母对孩子的引用将变为空。另外,如果我从孩子中删除 id 字段,那么父母双方的孩子都会存储在数据库中。
假设我现在有一个像这样的班级
Student{
String id;
final teacher = ToOne<Teacher>();
}
和另一个老师这样的班级,
Teacher{
@Unique(onConflict: ConflictStrategy.replace)
String? id;
@Backlink()
final students = ToMany<Student>();
}
如果我尝试执行类似的操作
student1.teacher.target = teacher1
,
student2.teacher.target = teacher1
那么如果我尝试检查学生1,那么它的老师将为空。为什么 ?
I have two objects one parent model have ToOne
relation and a child model with ToMany
relation back to the parent. Now if I have two parents who are setting their relation to child then the first parent's reference to child is getting null when the second parent reference is set. Also, if I remove the id field from the child then both parents child is stored in the database.
Suppose I have a class like
Student{
String id;
final teacher = ToOne<Teacher>();
}
and another class Teacher as
Teacher{
@Unique(onConflict: ConflictStrategy.replace)
String? id;
@Backlink()
final students = ToMany<Student>();
}
so now if I try to do something like
student1.teacher.target = teacher1
followed by
student2.teacher.target = teacher1
then if I try to check for student1 then its teacher is getting null. Why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论