How to hide relation API endpoints from explorer? ex. GET /parents/{pk}/childs
I have two models Parent and Child and relation like this.
Parent --> hasAndBelongsToMany --> Child Child --> hasAndBelongsToMany --> Parent
and I got
GET /Parents/{id}/students GET /Parents/{id}/students/{pk} GET /Parents/{id}/students/rel/{pk} ... etc.
I can hide GET /parents with.
Parent.sharedClass.find('find', true).shared = false;
How about relations to child model the code below not working?
Parent.sharedClass.find('__get__students', true).shared = false;
OR
Parent.sharedClass.find('__get__students', false).shared = false;
I have the same question.. Seems like there is no loopback developers.
AFAIK, the relation methods are created when the model is attached to a datasource, which happens later in the application lifecycle. To disable a relation method, you have to make the change after the model was attached.
Parent.on('attached', function() {
Parent.sharedClass.find('__get__students', false).shared = false;
});
@raymondfeng @ritch I remember one of you was commenting on this same problem elsewhere, could you please confirm the solution above is the correct one?
@crandmck please update the documentation once a working solution is confirmed.
@bajtos It won't work currently. check discuss on https://github.com/strongloop/loopback/issues/410, https://github.com/strongloop/strong-remoting/issues/94, and PR https://github.com/strongloop/strong-remoting/pull/95
Parent.on('attached', function() { Parent.sharedClass.find('__get__students', false).shared = false; });
Seems as though ".find" above returns a Class one level higher than needed for this purpose. I had to access ".fn" to get this to work.
Parent.sharedClass.find('__get__students', false).fn.shared = false;
Can you try https://github.com/strongloop/loopback/blob/master/lib/models/model.js#L392?
IT DOES WORK... Ignore my comment here below... I had omitted the second Argument that Ritchie mentions in his comment below...
Sorry...
I tested that and it DOES NOT work Raymond... I then use the technique I outlined in my comment and it does work...
It certainly would be the cleaner way to do it though...
On Thu, Oct 2, 2014 at 11:13 AM, Raymond Feng [email protected] wrote:
Can you try https://github.com/strongloop/loopback/blob/master/lib/models/model.js#L392 ?
— Reply to this email directly or view it on GitHub https://github.com/strongloop/loopback/issues/563#issuecomment-57675912.
As of loopback 2.4.0 you can do:
var isStaticMethod = false;
Parent.disableRemoteMethod('__get__students', isStaticMethod);
@bajtos @tonysoft @clarkorz @cajoy
I just confirmed it works with latest loopback. In my case, I added common/models/post.js:
module.exports = function(Post) {
Post.disableRemoteMethod('__get__tags', false);
Post.disableRemoteMethod('__create__tags', false);
Post.disableRemoteMethod('__delete__tags', false);
};
The three relation methods to tags are now disabled in the api explorer.
WOW!!!! thx for your hard work. I wanna add more than 1 star on LB.