Update Specific Record - Where Clause - Objective C

So,

Totally new at backendless and the way that I learn is a build a simple little CRUD to see how things tie together. So far so good. However, I’m a little stuck on the best approach for updating one item within an object.

I’m seeing two different ways to update, however, unless I’m missing something both ways would update the entire datastore. Correct? Where would I specify a where clause? What I would like to do is just update a specific record. I have two functions I believe doing the same thing just differently. If you could point me in the right direction that would be excellent. Remember I’m new.

I’m using Aircraft as an example below;

-(void)updateAircraft:(Aircraft *)aircraft

{

Responder *responder = [Responder responder:self

                         selResponseHandler:@selector(responseHandler:)

                            selErrorHandler:@selector(errorHandler:)];

aircraft.AircraftRego = @"VH-OLB?";

aircraft.AircraftType = @"Cessna";

id<IDataStore> dataStore = [backendless.persistenceService of:[Aircraft class]];

[dataStore save:aircraft responder:responder];

}

#pragma mark - responder

-(id)responseHandler:(id)response

{

NSLog(@"%@", response);

return response;

}

-(id)errorHandler:(Fault *)fault

{

NSLog(@"%@", fault.detail);

return fault;

}

-(void)updateAircraft2{

[backendless.persistenceService first:[Aircraft class]

response:^(Aircraft *result) {

result.NextServiceAirframe = [backendless randomString:MIN(25,500)];

result.AircraftRego = [backendless randomString:MIN(25,500)];

result.AircraftActive = [backendless randomString:MIN(25,500)];

result.AircraftType = [backendless randomString:MIN(25,500)];

result.NextServiceEngine = [backendless randomString:MIN(25,500)];

[backendless.persistenceService save:result response:^(Aircraft *result)

    {

        } error:^(Fault *fault)

            {

        

            }];

        } error:^(Fault *fault)

            {

        

    }];

}

In parse I did something like this (where selectedRego is a variable being passed in dynamically);
PFQuery *query = [PFQuery queryWithClassName:@“Aircraft”];
[query whereKey:@“AircraftRego” equalTo:selectedRego];

        [query getFirstObjectInBackgroundWithBlock:^(PFObject *aircraftObject, NSError *error) {

}

Thanks!

Hi Jeremy,

I’ll response as I read your post. Let’s start with the first question:

I'm seeing two different ways to update, however, unless I'm missing something both ways would update the entire datastore. Correct? 

No, this is not correct. There is only one way to update an object (calling the save method) and it will update just the object and any related objects you save. The term “data store” is a abstract reference to the table which contains the data object.

Where would I specify a where clause? 

You specify it in the BackendlessDataQuery class, just like the documentation describes it:
http://support.backendless.com/public/attachments/4d9b542c99b4a5d4574087aea8bd127a.png</img>

Now onto your code. I made a few annotations. All it takes is just read through the sample code, I think it is self-explanatory, just see what it does…

What you though was “approach 1”:
http://support.backendless.com/public/attachments/17db42200dafb5dd6bb7b15a5fd266df.png</img>

And now what you thought was “Approach 2”, which in reality is the same thing as “Approach 1”:
http://support.backendless.com/public/attachments/9069b745c2784d2bc485cf5224bcb552.png</img>

Hope this helps.

Mark

Hi Mark,

Right…I knew there was a way I simply wasn’t seeing it/didn’t quite understand it. So getting the first allows me to update later if required. Got it. This then wouldn’t update everything just the one record. Btw i’m really liking how quick the service is. Nice. Now to fight with dates.

Thanks man!

Jeremy