2016-11-02 3 views
0

ich geerbt ModellWarum funktioniert ein Loopback nicht?

{ 
    "name": "user", 
    "plural": "users", 
    "base": "User", 
    "relations": { 
    "roles": { 
     "type": "hasMany", 
     "model": "Role", 
     "foreignKey": "principalId", 
     "through": "RoleMapping" 
    } 
    }, 

Und Haken erstellen, für die mit Benutzern Speicher Rolle

UserModel.afterRemote('create', (context, user, next) => { 
     let body = context.req.body; 
     if (!body.hasOwnProperty('roleId')) { 
      next(); 
     } 
     Role.findById(body.roleId) 
      .then(role => { 
      if (!role){ 
       next(); 
      } 
      return user.roles.add(role); 
      }) 
      .then(roleMapping => { 
      next(); 
      }); 
     }); 

Und Rekord zu db (Mongo) successfuly hinzugefügt, aber während Anfrage

/api/users?access_token={}[include]=roles 

Rekord GET nicht beigetreten, warum?

Antwort

-1

Ihre Abfragezeichenfolgeflag ist falsch das sind Filter sollte

/api/users?access_token={}&filter[include]=roles

(include filter)

sein