ios - Magical Record relationship return empty objects -
My model has two types of objects - say children
and parent
. I get them in the JSON in the JSON server from the server like this:
{"kids": [{"id": 1, "parent": [{"id" : {"Id": 1}, {"id": 2}]}]}
As you can see, children
have lots of
related parents
objects. I am using a magical record to store the date, and I have to be able to get the kid.parents
object in the core data model.
While getting them from the server, I am using this code:
for (NSDIP + Kidict in Object) {NSN * OID = Childdict [ "Id"]; // I am using 'OID' in OBJE-C, when the 'id' keyword Kid * child = [Kid MR_FindFirstBitTribute: @ Value with OID] is required to be used; If (child == blue) {children = [Kid MR_sacket entity]; } [Child Update: Kiddict]; [Self Update ParentsFromArray: kidDict [@ "Parents"] Forkid: Children]; } [[NSMNEDAbjectActactMR_DefaultContacts] MR_SEVTOpercentStoreEquoice]; // ... + (zero) UpdatePrintFrayRay: (NSARRA *) Kid for parents: (Children *) Children {// Clean the existing relationship NSSet * Child Claim = [Child. Kidnappers copy]; (Parents * Parents' Parents) {[Child Deletion Parents: Parents]; } (NSplayer * Parent Dict in iTech) {NSNM * OID = Parent Dict [@ "ID"]; Parents * Parent = [Guardian MR_FindFirstBeativity: @Price with "OID": OID]; If (! Parents) {parent = [parent mr_security entity]; } [Parents Update: Parent Dict]; // Update current object to catch all server changes for this [child addParentsObject: parent]; }} // Child and Parent Update Method - (zero) updateFromDictionary: (NSDictionary *) Dictionary; {NSMutableDictionary * dict = [dictionarycopy]; If (dictionary [@ "id"]) self.oid = dict [@ "OID"]; }
However, when I want to get the kid.parents
, then I have to return the empty objects array. So first for the child, this Parents give
, for the second child it gives two ode == zero
with parent
, with both zero
Properties I simplified the code for better readability, both the objects have many other properties, and these are all zero.
Why is this happening? Am I doing something wrong with saving? I have found, but it seems that my classes are right.
First of all, I do not think this block of code actually does anything ...
// NSSet clear of existing relationship * Child's claim = [Child. Kidnapper copy]; (Parents' parents parents) {[child's parents]; }
If you want to clear relationships, you can reduce only several sides and everything will be disconnected. However, the data is not deleted unless you explicitly delete it. To help you, find the -MR_deleteEntity
method.
Second, I like to use the parent.kid = kid
syntax instead of [child addParentsObject: parent]
one-to-many When using a relationship,
Third, there is no need to create inappropriate words in your data dictionary in your update form method.
Fourth, the real problem may be that you are not setting proper dictionary subsets in the updateFromDictionary method. It seems that you are only passing in the top level dictionary and there is no specific information of parents. You can tell this because you are still receiving non-objects, but there is no data if the data-check is a cheap one that the data is not included in the dictionary passed.
On one note, I mention that the magical record already has the import code written for you, you just have to map the source data of the coredata model. These mappings are in user information dictionary in the unit model file (currently) I suggest that a brief (abbreviated)
Comments
Post a Comment