2016-07-02 5 views
0

、エンティティは次のスキーマに存在している:アンドロイドGreenDao

Entity image =schema.addEntity("Image"); 
    image.setTableName("Images"); 
    image.addStringProperty("id").primaryKey(); 
    image.addStringProperty("url"); 


    Entity community = schema.addEntity("Community"); 
    community.setTableName("Communities"); 
    community.addStringProperty("id").primaryKey(); 
    community.addStringProperty("title"); 
    community.addStringProperty("imageId"); 


    Entity user=schema.addEntity("User"); 
    user.setTableName("Users"); 
    user.addStringProperty("id").primaryKey(); 
    user.addStringProperty("fullName"); 
    user.addStringProperty("imageId"); 

    Entity relation=schema.addEntity("Relation"); 
    relation.addStringProperty("userId"); 
    relation.addStringProperty("communityId"); 

ではなく、単にIMAGEIDの関連オブジェクト全体イメージを、返すためにGreenDaoで可能ですか?あなたはこのような.addToOneとの関係構築する必要が文字列としてIMAGEIDを設定する

答えて

0

Insetad:user.getPicture(と

Property imageIdProperty = user.addLongProperty("imageId").getProperty(); 
user.addToOne(image, imageIdProperty); 

)を使用すると、代わりに画像オブジェクトとして画像を得ることができる必要がありますIDの

編集:ユーザーに複数の画像が必要な場合は、ToMany関係を使用します。あなたは、そのコミュニティ内のすべてのユーザーに

+0

を取得する必要があります)

Property communityId = user.addLongProperty("communityId").getProperty(); ToMany communityToUsers = community.addToMany(user, communityId); 

community.getUsersで(:あなたはこのようToMany関係を使用してみてください、あなたの関係について

http://greenrobot.org/greendao/documentation/relations/

それはgreendaoのドキュメントで行うのかを確認することができます画像をありがとう、関係のテーブルが大丈夫か、ユーザーが多くのコミュニティに参加でき、コミュニティに多数のユーザーが含まれている可能性があるため、ToManyをユーザーとコミュニティに対して実装する必要があるかどうか教えてください。 – vasile

+0

あなたのユーザコミュニティ関係の解決策を追加しました – babadaba

+0

ありがとう – vasile

関連する問題