loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Included models not accessible in afterRemote hook

Open bryannaegele opened this issue 11 years ago • 4 comments

When including the user object during a login, attempting to access the user object in an afterRemote hook is not intuitive. The full object graph is evaluated when doing a console.log and in the response, but I cannot seem to find a way to access the included model with normal object syntax.

console.log(accessToken); // outputs the entire object graph

console.log(accessToken.user); 
/* outputs
{ [Function]
  getAsync: [Function],
  update: [Function],
  destroy: [Function],
  create: [Function],
  build: [Function],
  _targetClass: 'user' }
*/

I assume the user is not evaluated by the time I'm attempting to access it. Am I missing something simple? It would be intuitive to me that the entire graph is available in the afterRemote hook.

bryannaegele avatar Jun 01 '15 21:06 bryannaegele

Call accessToken.toJSON().user

raymondfeng avatar Jun 01 '15 21:06 raymondfeng

Thank you @raymondfeng. This would be great to add to the docs under Querying data and the remote hooks sections.

bryannaegele avatar Jun 01 '15 22:06 bryannaegele

See http://docs.strongloop.com/display/LB/Include+filter#Includefilter-Accessincludedobjects

raymondfeng avatar Jun 01 '15 22:06 raymondfeng

Hi:

Do you know if upsert method is available ???

Best Regards

alejandrohenriquez avatar Jul 02 '16 13:07 alejandrohenriquez