0

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 ?

minato
  • 2,028
  • 1
  • 18
  • 30
  • 1
    Could you please give additional details what you are doing (e.g. code examples) and also detail your expectations? – Markus Junginger Mar 22 '22 at 16:10
  • @MarkusJunginger I have added an example – minato Mar 23 '22 at 06:07
  • I tried to reproduce what you describe with your example and cannot. The `target` setter is assigning values as expected. Perhaps try including a fully reproducible example of your issue with full entities and how you're trying to access the database etc... – Loren.A Mar 24 '22 at 00:52
  • 1
    I found out that I was trying "insertAll" to persist in local, so when I changed it with single "insert" for each model it worked. – minato Mar 24 '22 at 09:05

0 Answers0