The problem is probably that eve2 doesn't have an _id yet.
Before calling appdata.save on event, call it on eve2. Then, after eve2 is saved, in the onSuccess callback, call event.initReference(arg0), and then use appdata to save event.
For these to work, both entities must be saved to your backend, which will create a unique _id for them.
05-06 13:55:47.372: W/System.err(3901): at org.pac.mypac.kunvey2.HelloEntity.initReference(HelloEntity.java:117)
05-06 13:55:47.372: W/System.err(3901): at org.pac.mypac.kunvey2.Main.storeDataOnKinvey(Main.java:1028)
05-06 13:55:47.372: W/System.err(3901): at org.pac.mypac.kunvey2.Main$myAsyncTask2.doInBackground(Main.java:137)
is there something wrong in my code ???
E
Edward
said
almost 7 years ago
Hey,
`KinveyReference`s are used to create a reference between two entities possibly across collections. So, using your data, you could have a `MyEntity` in `Collection_1`, the contains a reference to a `NewEntity` in `Collection_2`.
So, within your `MyEntity`, there is a `private KinveyReference invitations;`, as well as that `initReferences(...)` method.
First, there are a couple issues with that `initReferences(...)` method. It looks like it takes an `InvitationEntity` instead of a `NewEntity`, and assumes the collection is `TestTableWin` instead of `Collection_2`.
then, in the second code snippet, both a `MyEntity` and a `NewEntity` need to be created, and then call `event.initReference(myNewEntit)`, which will set the reference. Then, after that, call save.
Does that make sense?
v
vikash singh
said
almost 7 years ago
Hello Edward,
thanks for your response,
we create tw o model class as MyEntity, NewEntity. and created two different collection Collection_1, and Collection_2.
I defined KinveyRefernce in my MyEntity class, and intialize initReference(NewIntity newentityobj)
public void initReference(InvitationEntity myInvitation){
KinveyReference reference = new KinveyReference("TestTableWin", myInvitation.get("_id").toString());
this.invitations = reference;
}
With this code we can save data to Collection_1, but i want to save data to my second Collection_2 as well.
But, i am not able to find its proper code, how to store relational data to two different collection using AppData.save method,
C
Caroline
said
almost 7 years ago
Hi Vikash,
Have you seen our CTO's post about [data modeling in Kinvey](http://www.kinvey.com/blog/3732/data-modeling-in-kinvey "data modeling in Kinvey")? Is there some specific Android topic you wanted more information about?
vikash singh
1 person has this question