1

i am trying to sync my project to parse. right now i am saving my data in core data. i have 2 kind of entities: Night and Session. it's look like this: Night have many session and session have one night. enter image description here

when i want to add session to night i create or fetch night and add new session. this way i can get from my night all the session and the opposite way. in order to uploading it to parse i have added in the "Session" table "Night" column ( of type Pointer ) and in "Night" table i added "Sessions" column ( of type relation ) this is how it's look like:

enter image description here
enter image description here enter image description here

i already succeeded to sync all the record from parse to Core data EXCEPT the relation and Pointers. my problem is that the only solution for that ( insert this relation into core data ) is to create new night ( i mean create instance ) and create new sessions and add them like this:

-(void)addSession:(Session *)session toNight:(Night *)night {
    if (session && night) {
        NSMutableSet * sessionSet = [night.sessions mutableCopy];
        [sessionSet addObject:session];
        night.sessions = sessionSet;
    }
}

So my Question is:

  1. this is the only way? create instance and add them?
  2. when i add Session to Night or when i add Night to session, why it's not shown in the DB table. i can not see this connection. ( like i see in parse ,relation and pointers)
  3. when i get the Relation from parse it's look like this:

sessions = { "__type" = Relation; className = Session; };

what i can do with that?

Thanks for reading this long Question and i hope i was clear :)

BTW: i follow this tutorial and they do not have relation and pointers.

Updatde i am using Parse Rest Clint API.

2 Answers 2

2

this is the only way? create instance and add them?

yes. either you create a night object and set its sessions property; or you create a session object and set its night property. (provided you have defined and inverse in your core data model).

when i add Session to Night or when i add Night to session, why it's not shown in the DB table. i can not see this connection. ( like i see in parse ,relation and pointers)

this is not clear to me. What would you like to see in the DB table? if you add a bunch of sessions to a night, or you set the night property on session object, then when you inspect those object (reap. night - session) you can access the properties and should show the right value...

when i get the Relation from parse it's look like this:

In Parse, you do not need to model both the Pointer and the Relation (as it happens in Core Data where you have a relation and its inverse).

You just need the pointer for a one to many relationship. Parse relations are used from many to many relationships.

So, what you should to store all of the sessions in Parse is fetching them through a query like:

PFObject* night ...
PFQuery *query = [PFQuery queryWithClassName:@"Sessions"];
[query whereKey:@"night" equalTo:night];

then [query findObjects...] will give you an array of sessions you can add in a go to your Night Core Data object. (so, no need to call multiple time addSession:).

Hope this helps.

Sign up to request clarification or add additional context in comments.

4 Comments

i am using Parse Rest clint API.
well, my remark holds still even if you are using the REST API. Check parse.com/docs/rest#queries-relational at the Relational Queries section to find the equivalent (you will need to give night objectId explicitly)
Thanks for you quick response :) but correct me if i'm wrong, your answer is for my third question, right? "how i get the Relation from parse?"
You are right, in my mind, the really important question was the third... :-) anyway, I added answers for the other 2 questions...
0

This is just answer to my first question: i follow this article and i found this quote:

Core Data cannot operate on data without loading the data into memory.

so i guess i solved my first question. Yes i have to load the data into my memory and then make the connection.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.