简体   繁体   English

如何使用ActiveAndroid读写外键?

[英]How do I read-write foreign keys using ActiveAndroid?

In ActiveAndroid, I can build relationships by directly referencing the POJO. 在ActiveAndroid中,我可以通过直接引用POJO来建立关系。 For instance, if House had many Window s, this would be fairly straightforward. 例如,如果House有许多Window ,这将非常简单。

Rather than using this direct reference, is there a way to manually set the foreign key and still be able to ActiveAndroid Select later on? 除了使用此直接参考,还有没有办法手动设置外键,并且以后仍然能够使用ActiveAndroid Select

The reason for this is that we are performing data syncing from the server to Android. 原因是我们正在执行从服务器到Android的数据同步。 The data comes in JSON, but rather than being nested the data already comes with foreign keys. 数据以JSON格式提供,但不是嵌套,而是已带有外键。 I would like to set the foreign keys to our data models without diving too deep into SQLite code. 我想为我们的数据模型设置外键,而不必深入研究SQLite代码。


UPDATE to @ssh's answer : 更新到@ssh的答案

I am not trying to dynamically change the database structure. 我没有尝试动态更改数据库结构。 Rather, I would like to manually set the foreign key of my models. 相反,我想手动设置模型的外键。 My assumption is that ActiveAndroid wraps around foreign key queries to directly access other objects that are defined as attributes. 我的假设是ActiveAndroid围绕外键查询直接访问定义为属性的其他对象。 Is there a way to access that foreign key table directly? 有没有办法直接访问该外键表?

Thanks for the current answer - I'll look more into setting that value in the foreign key column directly using SQLite. 感谢您提供当前的答案-我将进一步研究直接使用SQLite在外键列中设置该值。

ActiveAndroid does not support a mechanism for dynamically changing database structure. ActiveAndroid不支持动态更改数据库结构的机制。 It is inconvenient, but this is true. 这很不方便,但这是事实。 If you want to change your database structure the only way to do that is execute SQLite query. 如果要更改数据库结构,唯一的方法是执行SQLite查询。

It can be possible via reflection, using dynamically adding annotation, but Java is not supported this . 可以通过反射,使用动态添加注释来实现,但是Java不支持this

For change column name you can use this thread . 对于更改列名称,您可以使用此线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM