Skip to content Skip to sidebar Skip to footer

Ormlite Android Foreign Key Support

I am not clever from ORMlite documentation. Is is possible to declare in class, that this parameter is foreign key? e.g. I have table Customer: @DatabaseTable(tableName = 'customer

Solution 1:

AccountNameHolder should aim towards DatabaseField name from table Accounts. How to do that?

I'm not exactly sure what you want but possibly you should change your foreign field to be the actual type instead of a name:

@DatabaseField(foreign = true)private Account account;

Internally, ORMLite will store a account_id field (maybe the string name) in the Customer table but you don't have to worry about that. Remember that when you query for a Customer, the Account that is set on the account field will just have the id field set. To have ORMLite also lookup the account you will need to set the foreignAutoRefresh=true.

As @Lalit pointed out, here is some documentation on this subject. We've spent a long time on the documentation so it should be helpful.

Also, there is some example code about foreign fields.

Hope this helps.

Post a Comment for "Ormlite Android Foreign Key Support"