3

ドキュメントで指定されているように、オブジェクトを作成し、それらのプロパティを入力して、データ ストアにリンクを保存します。

public class InvitationEntity extends GenericJson {
    @Key
    public String objectId;
    @Key
    public int status;
    @Key("_id")
    public String id;
    @Key
    public String name;
}
public class EventEntity extends GenericJson {
    @Key
    public String name;
    @Key
    public String eventDate;
    @Key
    public String location;
    @Key
    public String tip;
    @Key
    public KinveyReference invitations;

    public void initReference(InvitationEntity myInvitation){
        KinveyReference reference = new KinveyReference("invitationCollection", myInvitation.get("_id").toString());
        this.invitations = reference;
    }
}

...

 InvitationEntity invitationEntity = new InvitationEntity();
 invitationEntity.name = "3";
 invitationEntity.objectId="3";
mKinveyClient.appData("invitationCollection", InvitationEntity.class).save(invitationEntity, new KinveyClientCallback<InvitationEntity>() {
                @Override
                public void onSuccess(InvitationEntity invitationEntity1) {
                    Log.e("my", "Ok1 " + invitationEntity1.toString());

                    EventEntity eventEntity = new EventEntity();
                    eventEntity.tip = "33";
                    eventEntity.initReference(invitationEntity1);
                    mKinveyClient.appData("eventCollection", EventEntity.class).save(eventEntity, new KinveyClientCallback<EventEntity>() {
                        @Override
                        public void onSuccess(EventEntity eventEntity_rez) {
                            Log.e("my", "Ok2 " + eventEntity_rez.toString());
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            Log.e("my", "Failed to save entity " + t.getMessage());
                        }
                    });
                }

                @Override
                public void onFailure(Throwable t) {
                    Log.e("my", "Failed to save entity " + t.getMessage());
                }
            });

今私は要求します:

    Query q = mKinveyClient.query();
    mKinveyClient.appData("eventCollection", EventEntity .class).get(q, new KinveyListCallback<EventEntity >() {
        @Override
        public void onSuccess(EventEntity [] resalt) {
                Log.d("my", resalt[0].toString());
        }

        @Override
        public void onFailure(Throwable t) {
            Log.d("my", "Error fetching data: " + t.getMessage());
        }
    });

私は結果を受け取ります:

{"invitations":{"_collection":"invitationCollection",
                            "_id":"52715e5b13dde23677021c80",
                            "_type":"KinveyRef"},
"tip":"33",
"_acl":{"creator":"526182566bbfcbf429000518"},
"_kmd":{"lmt":"2013-10-30T19:30:36.086Z",
                 "ect":"2013-10-30T19:30:36.086Z"},
"_id":"52715e5c13dde23677021c81",
"kid":"kid_TTpvqRShiO",
"collection":"eventCollection"}

そして、受け取ることが望ましいでしょう:

{"invitations":{"_id":"52715e5b13dde23677021c80",
                             "name":"3",
                             "objectId":"3",
                             "status":0,
                             "_acl":{"creator":"526182566bbfcbf429000518"},
                             "_kmd":{"lmt":"2013-10-30T19:30:35.912Z",
                                               "ect":"2013-10-30T19:30:35.912Z"},
                                               "kid":"kid_TTpvqRShiO",
                                               "collection":"invitationCollection"},
"tip":"33",
"_acl":{"creator":"526182566bbfcbf429000518"},
"_kmd":{"lmt":"2013-10-30T19:30:36.086Z",
                 "ect":"2013-10-30T19:30:36.086Z"},
"_id":"52715e5c13dde23677021c81",
"kid":"kid_TTpvqRShiO",
"collection":"eventCollection"}

その中のリンクの代わりに他のオブジェクトがあったようにオブジェクトを受け取る方法は?

4

1 に答える 1

1

私は Kinvey のエンジニアであり、これについてあなたを助けることができます。私はサポート フォーラムに同じ回答を投稿しましたが、他の誰かがここでそれに出くわすかもしれないと考えました:

それは不可能ではありません!

Appdata には、Get メソッドと GetEntity メソッドの複数のバリエーションがあります。ここで Javadocs をチェックしてください: http://devcenter.kinvey.com/android/reference/api/reference/com/kinvey/android/AsyncAppData.html

KinveyReferences を解決するには、解決したいフィールドの名前を含む String[] を get メソッドの 2 番目のパラメーターとして渡します。

mKinveyClient.appData("eventCollection", EventEntity .class).get(q, new String[]{"invitations"}, new KinveyListCallback() { ... }

これで、onSuccess コールバックは EventEntity を返しますが、参照は解決され、次を呼び出すことができます。

InvitationEntity myInvite = results[0].getInvitations.getTypedObject(InvitationEntity.class);
于 2013-10-31T15:39:40.273 に答える