ORMlite Android的外键的支持 [英] ORMlite Android foreign key support

查看:156
本文介绍了ORMlite Android的外键的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是从ORMlite文档聪明。是否可以在课堂上宣布,这个参数是外键?

例如。我有表客户:

  @DatabaseTable(tableName值=客户)
 公共类客户
{
  @DatabaseField(ID =真)
  私人字符串客户名称;

  @DatabaseField
  私人字符串customerSurname;

  @DatabaseField(外资=真)
  私人字符串accountNameHolder;

  @DatabaseField
  私人诠释年龄;

  公众客户()
  {

  }
}
 

AccountNameHolder的目标应该是实现DatabaseField的名字从表帐户。如何做到这一点?我发现的唯一参数外资=真实的,但并没有什么约,它的参数和从该表中它重新presents。

感谢

解决方案
  

AccountNameHolder的目标应该是实现DatabaseField的名字从表帐户。那怎么办?

我不太确定你想要什么,但你可能要改变你的洋场是实际的键入的,而不是名称:

  @DatabaseField(外资=真)
私人帐户的帐户;
 

在内部, ORMLite 将存储 ACCOUNT_ID 字段(可能字符串名称)在客户表,但你不必担心。请记住,当你查询一个客户帐户,它被设置在帐户字段就只能id字段集。有ORMLite也查找了帐户,您将需要设置 foreignAutoRefresh = TRUE

由于@Lalit指出,这里是对这个问题的一些文件。我们已经花了上的文档很长的时间,所以它应该是有帮助的。

此外,还有一些例如code对外国领域

希望这有助于。

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")
 public class Customer
{
  @DatabaseField(id = true)
  private String customerName;

  @DatabaseField
  private String customerSurname;

  @DatabaseField(foreign = true)
  private String accountNameHolder;

  @DatabaseField
  private int age;

  public Customer()
  {

  }
}

AccountNameHolder should aim towards DatabaseField name from table Accounts. How to do that? I have found only parameter foreign = true, but there is nothing about, which parameter and from which table it represents.

Thanks

解决方案

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.

这篇关于ORMlite Android的外键的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆