What's the related model method names in remote hooks?

24 views
Skip to first unread message

Hanzhi Dou

unread,
Nov 25, 2015, 2:46:09 AM11/25/15
to LoopbackJS
Hi,

I have a FitUser model extended from User model and defined a self through relationship.

       
"followers": {
            "type": "hasMany",
            "model": "FitUser",
            "foreignKey": "followeeId",
            "keyThrough": "followerId",
            "through": "FitFollow"
        },



ACL definition as below works.

{
            "principalType": "ROLE",
            "principalId": "$owner",
            "permission": "ALLOW",
            "property": "__get__followers"
        }

I need define an afterRemote hook for followers method (also other similar methods) to filter out some fields, the below definition does not work.

FitUser.afterRemote('__get__followers'function(context, user, next) {

        console.log('> fitUser.__get__followers triggered.');

        console.log('> result:' + JSON.stringify(context.result));
       // ...

        next();

    });



If I changed the '__get__followers' to 'get followers' , 'getFollowers', or '.followers', the code will not be executed either.   The code will be executed only when using '**', but that's not what i want.


What is the right way?


Thanks!

Hanzhi


Hanzhi Dou

unread,
Nov 25, 2015, 4:01:05 AM11/25/15
to LoopbackJS
I just make it work by using 'prototype.__get__followers'.

在 2015年11月25日星期三 UTC+8下午3:46:09,Hanzhi Dou写道:
Reply all
Reply to author
Forward
0 new messages