i have 2 tables 1 lists , 1 cars.
the list table has relationship cars. 1 list can contain many cars in column carsinlist. column carsinlist used type array.
what best query cars 1 list? should use unique key 1 list , cars in list? think there must better way because in parse.com backend can see many cars stored in column carsinlist.
thanks help!!
i'm assuming each user has own list of cars? strength of following method generate 1 api request. don't need use pfrelation.
let's have class called "list". can create column called "userid" user's objectid value query list object by.
pfobject* list = [pfobject objectwithclassname@"list"]; pfuser* currentuser = [pfuser currentuser]; [list setobject:currentuser.objectid forkey:@"userid"];
you can add single "car" object pointer "list" object:
pfobject* car = [firstquery getfirstobject]; // assuming query has been created [list addobject:car forkey:@"cars"]; [list save];
or can add multiple "car" objects pointers "list" object:
nsarray* cars = [secondquery findobjects]; // assuming query has been created [list addobjectsfromarray:car forkey:@"cars"]; [list save];
now query object follows. make sure use includekey: method.
pfquery* query = [pfquery querywithclassname@"list"]; [query wherekey:@"userid" isequalto:currentuser.objectid]; [query includekey:@"cars"]; // make sure include when pulling array of pointers pfobject* list = [query getfirstobject]; nsarray* cars = [list objectforkey:@"cars"];
notice can pull array of "car" objects "list" object via includekey: method. should noted addobject:forkey: augment existing array. can add fresh array of pointers object via setobject:forkey: method.