Hi all,
I am developing an small android application in which I use ORMLite to work with sqlite db.
I have object A with have one-many relationship to B like below
class A {
@DatabaseField(generatedId=true)
private int id;
@DatabaseField
private String name;
@DatabaseField
private String surname;
@ForeignCollectionField
private Collections<Phone> phones;
}
class B{
@DatabaseField(generatedId=true)
private int id;
@DatabaseField
private String number;
@DatabaseField
private String type;
}
I can save A and all its belonged B by get DAO object of A and call Dao.createOrUpdate(A) .
The problem is, in table B, foreign key (to A) is 0 which properly it's not correct. (they should be A's Id)
Could you guys help me how to fix that?
Do I need to save A, get its generated id , update to all its children B and then update the DB manually?
Thanks,
Regards,
Toan