One to many relationship

31 views
Skip to first unread message

Toan Tran Tuong

unread,
Oct 29, 2014, 11:18:50 PM10/29/14
to ormlite...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages