angular-restmod icon indicating copy to clipboard operation
angular-restmod copied to clipboard

`mask` attribute ignored on related models

Open jacek-dargiel opened this issue 10 years ago • 2 comments

If a resource has a defined relation with another resource, then setting a mask attribute doesn't work. For example:

 angular.module('mapping')
  .factory('UserResource', function (restmod) {
    return restmod.model('/api/users').mix({
      'Profile':{
        belongsTo: 'ProfileResource',
        mask: 'CU'
      },
      'Posts':{
        belongsToMany: 'PostResource',
        mask: 'CU'
      }
    });
  })
  .factory('ProfileResource', function (restmod) {
    return restmod.model('/api/profile');
  })
  .factory('PostResource', function (restmod) {
    return restmod.model('/api/users');
  });

Using the above code, if you get a user using var user = UserResource.$find(1), and then save it using user.$save(), the actual request has profile_id, and post_ids attributes sent, ignoring the U flags.

jacek-dargiel avatar Jan 08 '16 14:01 jacek-dargiel

I ran into this same problem. Turns out, https://github.com/platanus/angular-restmod/commit/764b562e3a90617e11ab0558b49aa2e7ef562005 broke this functionality because the relation attribute mapping will now happen after your mask mapping. Since the relationship mapping explicitly sets the mask on your relation, it overwrites your mask. For now version 1.9 still functions correctly with the old behavior

jpulec avatar Apr 19 '16 18:04 jpulec

You can separate it out in 2 mixins one with the masks and other with the relations as a work around?

utf4 avatar Nov 03 '16 19:11 utf4