最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to remove a relation (pointer) in a Parse.Object without deleting the related Object? - Stack Overflow

programmeradmin2浏览0评论

I have a relation from the a model called thisDrive of class Drives in a column called lastDrive, which is also a Drive. Sometimes I need to delete this relation, so nothing is related (undefined). How can I remove the relation from a single drive without deleting.

here is what I tried.

var thisDrive = app.drivesCollection.model[0];
var relation = thisDrive.attributes.lastDrive.relation('lastDrive'); // I'm not sure about this line here.... 
relation.remove('lastDrive'); // not sure again... 

at this point I would expect thisDrive.attributes.lastDrive to be empty, but it is not...

if I run thisDrive.attributes.lastDrive.remove() I will remove the Drive that is referenced by this relationship... which is bad.

any idea how to achieve this?

Thanks.

I have a relation from the a model called thisDrive of class Drives in a column called lastDrive, which is also a Drive. Sometimes I need to delete this relation, so nothing is related (undefined). How can I remove the relation from a single drive without deleting.

here is what I tried.

var thisDrive = app.drivesCollection.model[0];
var relation = thisDrive.attributes.lastDrive.relation('lastDrive'); // I'm not sure about this line here.... 
relation.remove('lastDrive'); // not sure again... 

at this point I would expect thisDrive.attributes.lastDrive to be empty, but it is not...

if I run thisDrive.attributes.lastDrive.remove() I will remove the Drive that is referenced by this relationship... which is bad.

any idea how to achieve this?

Thanks.

Share Improve this question edited Sep 16, 2014 at 22:40 Mr. Polywhirl 48.7k12 gold badges93 silver badges144 bronze badges asked Sep 16, 2014 at 22:28 otmezgerotmezger 10.8k21 gold badges68 silver badges92 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

I personally do not set column values to null. Originally empty columns are (undefines).Those correspond to nil in iOS. If you set a column to null that would return you an NSNull object not nil anymore.

In order to remove a relation you can unset the column and save.

user.unset("registrationVoucher");
user.save();

What you need to do is set the object's attribute to null and then save.

var thisDrive = app.drivesCollection.model[0];
thisDrive.set("lastDrive", null);
thisDrive.save();

OBJECTIVE-C VERSION

     PFQuery *query = [PFQuery queryWithClassName:@"yourClassName"];
                [query getObjectInBackgroundWithId:@"yourObjectId" block:^(PFObject *objConsult, NSError *error) {

                    if (!error) {
                        [objConsult removeObjectForKey:@"yourPointerKey"];
                        SDCommonService *monService = [SDCommonService new];
                        [monService saveIntoParse:objConsult andPinName:nil
                                     withDescription:@"text"
                                                    :^(id objectId) {
                                                        NSLog(@"%@",objectId);


                                                    }];

                    }
                    else{

                        NSLog(@"ERROR");
                    }
                }];

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论