ORMlite Android foreign key support

前端 未结 1 1885
粉色の甜心
粉色の甜心 2020-12-31 04:24

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:

@Data         


        
1条回答
  •  孤城傲影
    2020-12-31 04:56

    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.

    • Foreign objects
    • Foreign auto refresh

    Also, there is some example code about foreign fields.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题