mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.87k stars 840 forks source link

addElementTransformer after setTransformOnlyServerElements(true) results in local objects still getting transformed in 1.4.0. #1011

Open hanson-andrew opened 9 years ago

hanson-andrew commented 9 years ago

For example:

angular.module('app', ['restangular']).run(["Restangular", function (Restangular) {
  Restangular.setTransformOnlyServerElements(true);
  Restangular.addElementTransformer('items', false, function(obj) {
    if (!obj.fromServer) {
      console.debug("I wouldn't expect to get here");
    }
    return obj;
  });
  Restangular.one('items',0).get().then(function(c) {
    //do something.
  });
}]);

If you run this code, you'll see that you do in fact get local object in the transform callback. This appears to only be the case in 1.4.0, because I run the same code in 1.3.1 just fine.

This appears to be because the call for transformElem added a new parameter force:

config.transformElem = function(elem, isCollection, route, Restangular, force)

This value is hardcoded to be true in both of the restangularizeElem and restangularizeCollection methods.

It appears this change came from https://github.com/mgonto/restangular/issues/581 but callbacks to both addElementTransformer and extendModelalso go through the restangularizeElem and restangularizeCollection functions

Edit: fixed a typo.

grabbou commented 9 years ago

@mgonto can you confirm this issue occurred because of your change?

daviesgeek commented 8 years ago

Can you verify that this is still broken in 1.5.2?

raulcesar commented 7 years ago

@daviesgeek, I can confirm this is still broken in 1.5.2 as well as 1.6.1