restangular icon indicating copy to clipboard operation
restangular copied to clipboard

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

Open hanson-andrew opened this issue 10 years ago • 3 comments

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.

hanson-andrew avatar Jan 23 '15 16:01 hanson-andrew

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

grabbou avatar Feb 21 '15 11:02 grabbou

Can you verify that this is still broken in 1.5.2?

daviesgeek avatar Jun 17 '16 23:06 daviesgeek

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

raulcesar avatar Feb 22 '17 19:02 raulcesar