leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

UPDATE some columns (ie PATCH)

I tried to update a single column in one row by using an update_service and specifying the row _id and the column value. The row also contains 3 pointer columns which do not need to change.

It fires the "error" function rather than "success" suggesting that the "collname" hasnt been specified (but only for one of the 3 pointer columns).
I can't replciaate it now because I ended up setting every column as a work-around but it was something like "collname not specified for Employee" and I couldn't figure out how I would do that anyway

Why is this? I believe this is the correct way:

I've attached the table structure image. I want to update only the Rate column.
So I map _id and rate and call the update service.

Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

UPDATE some columns (ie PATCH)

Hello Steve,

Could you clarify what you have tried and what exactly does not work?
E.g. you can send us screenshots with JS/mapping you use.

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

UPDATE some columns (ie PATCH)

I have had to change the code now because it didnt work but based on the structure above, this is what I do now and it works:

(Note: $scope.categoryRate is defined in the local scope variables as an EmployeeCategoryRate from the Model, as per the attached image)

code
function update1rate(rate) {
$scope.categoryRate=rate;

Code: Select all

 var requestData = {}; 
 requestData = (function mapping4523($scope){ 
     var requestData = {}; 
     requestData.params = Apperyio.EntityAPI('RossTrustees_SchemeEmployeeRates_update_service.request.query', undefined, true); 
     requestData.data = Apperyio.EntityAPI('RossTrustees_SchemeEmployeeRates_update_service.request.body', undefined, true); 
     var categoryRate_scope = $scope.categoryRate; 
     requestData.params._id = categoryRate_scope._id; 
     requestData.data.Scheme.collName="Schemes&quot 
     requestData.data.Scheme._id = categoryRate_scope.Scheme._id; 
     requestData.data.Category.collName="Categories&quot 
     requestData.data.Category._id = categoryRate_scope.Category._id; 
     requestData.data.Employee.collName = "Employees&quot 
     requestData.data.Employee._id = categoryRate_scope.Employee._id; 
     requestData.data.Rate=categoryRate_scope.Rate; 
     return requestData; 
 })($scope); 

 // read more about using rest services: https://devcenter.appery.io/documentation/angularjs/rest-service/  
 Apperyio.get("RossTrustees_SchemeEmployeeRates_update_service")(requestData).then( 

     function(success){ // success callback 
         console.log("Updated rate"); 
     }, 
     function(error){ // callback to handle request error 
     }, 
     function(notify){ // notify callback, can fire few times 
     }); 

}
/code

But if you change it to update just the "rate" value then it gives the error I mentioned:

code
var categoryRate_scope = $scope.categoryRate;
requestData.params.id = categoryRate_scope.id;
requestData.data.Rate=categoryRate_scope.Rate;
return requestData;
/code

I expected the above code to update the Rate using the unique _id to locate the row. If the row had 50 columns and only that 1 changed, it woudl appear that I need to specify all 50 in order to do an update ?

Image Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

UPDATE some columns (ie PATCH)

It is impossible to update multiple items per one request, using request parameter "_id". Please look at this documentation, how to update multiple objects: https://devcenter.appery.io/documenta...

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

UPDATE some columns (ie PATCH)

I'm not updating "multiple items".

The _id param will be the id of one row only in the collection.
What I want to do is update the Rate column for that _id

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

UPDATE some columns (ie PATCH)

Hi Steve,

It seems you passed this column (like "Employee") but not passed a value(_id for specified collection).

If you don't to update a field - you don't need to pass it's name into update update request.

Please check (if you will have it again) in browser debugger your actual service request.
You can find details here: https://devcenter.appery.io/documenta...

Regards.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

UPDATE some columns (ie PATCH)

In that case you have to set only this request parameter. So you don't have to set another columns (oly _id and Rate)

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

UPDATE some columns (ie PATCH)

I'm confused Sergiy. My code above show only the _id and rate being set:

code
var categoryRate_scope = $scope.categoryRate;
requestData.params.id = categoryRate_scope.id;
requestData.data.Rate=categoryRate_scope.Rate;
return requestData;
/code

The other block of code is what I have to do as a workaround now because the 4-lines of code does NOT work. To make it work for now I have to do two requests: the first "reads" the current record using the _id and then I "update" using all of the column values but change the rate. This is not efficient.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

UPDATE some columns (ie PATCH)

Plese clarify, what is a value of the variable "categoryRate"?
It has to have two properties: _id and Rate.

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

UPDATE some columns (ie PATCH)

categoryRate is as per the last image above
if is a var based on the model "EmployeeCategoryRate"
There is an _id (for the DB table row),the rate and 3 pointers to other tables for Scheme,Employee and Category.

I want to update the rate for that one _id and do not need to update any of the 3 pointer columns. So this is what doesnt work and will execute the "function(error)"

code
var requestData = {};
requestData = (function mapping4523($scope){
var requestData = {};
requestData.params = Apperyio.EntityAPI('RossTrustees_SchemeEmployeeRates_update_service.request.query', undefined, true);
requestData.data = Apperyio.EntityAPI('RossTrustees_SchemeEmployeeRates_update_service.request.body', undefined, true);
var categoryRate_scope = $scope.categoryRate;
requestData.params.id = categoryRate_scope.id;
requestData.data.Rate=categoryRate_scope.Rate;
return requestData;
})($scope);

// read more about using rest services: https://devcenter.appery.io/documentation/angularjs/rest-service/
Apperyio.get("RossTrustees_SchemeEmployeeRates_update_service")(requestData).then(

function(success){ // success callback
console.log("Updated rate");
},
function(error){ // callback to handle request error
console.log("Failed to update rate");
},
function(notify){ // notify callback, can fire few times
});
}
/code

So perhaps I'm asking the wrong question. Let me re-phrase it please.
If I have a DB table with 20 columns, one of which will be a unique ID called "_id" and say one column called "number", what model/variables/code would work to set the "number" column to 100 using the _id without changing any of the other 18 columns?

Return to “Issues”