您好,我是 GreenDao 的新手,我真的很喜欢它,但是,我尝试使用 django REST API 和使用 GreenDao 实体进行 Retrfit 设置消息平台,并且我有来自服务器的 JSON 消息:
{
id: 1
created_at: "2015-10-06T02:45:48Z"
subject: "First message"
message: "Here is our first message across the messaging system! I feel just like Samuel Morse."
read: true
sender: {
url: "https://app.herokuapp.com/api/users/461"
username: "travis"
email: ""
is_staff: false
}
receiver: 81
}
问题是我如何将绿色 dao“发送者”中的消息对象作为用户对象而不是字符串或长消息对象中的对象放入消息对象中:
Schema schema = new Schema(DB_VERSION, ANDROID_APP_ID);
Entity privateMessage = schema.addEntity("PrivateMessage");
PropertyType user = schema.addEntity("User");
Property sender = privateMessage.addProperty(user., propertyName)
privateMessage.addStringProperty("id").primaryKey().unique();
privateMessage.addBooleanProperty("read");
privateMessage.addStringProperty("message");
user.addStringProperty("urlId").primaryKey().unique();
user.addStringProperty("url").unique();
user.addStringProperty("first_name");
user.addStringProperty("last_name");
user.addStringProperty("username").unique();
user.addStringProperty("email").unique();
user.addStringProperty("address");
user.addStringProperty("phone_number");
user.addStringProperty("password");
user.addStringProperty("group");
user.addBooleanProperty("sex");
user.addBooleanProperty("is_stuff");
user.addBooleanProperty("is_active");
user.addStringProperty("token");
user.addStringProperty("profile_picture");
user.addStringProperty("description");
user.addDateProperty("dob");
Property messagesThreatsId = privateMessage.addStringProperty("receiver").getProperty();
ToMany userToMessages = user.addToMany(privateMessage, messagesThreatsId);
Property conversations = privateMessage.addStringProperty("subject").getProperty();
Property created_at = privateMessage.addDateProperty("created_at").getProperty();
userToMessages.setName("LastMessages");
userToMessages.orderDesc(created_at);