You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
include for role mappings to different principalTypes #436
I read through the issues, the tests and the docs but I couldn't find a word about the possibility to e.g. include all users (but not applications or roles) of a role.
I'm currently building my app with LB1 but I have an on LB2 with migration in my mind. I already read about the polymorphic relations, but their aren't used yet in the Role -> RoleMapping -> User/Application/Role Model. Any ETA ?
and it worked since I got the following methods on the following classes:
on MyUser: __[findById, destroyById, ...]__roles, …
on MyApplication: __[findById, destroyById, ...]__roles, …
on MyRole: __[__findById, destroyById]__applications, …
so it seem to work on the model level.
But they don't show up in the Explorer, although e.g. MyApplication.sharedClass.find('__findById__roles', false).shared is true.
I guess that comes from the fact that the classes' relations were added "after" they were published.
Is there a way to republish all published classes ?
I extended Role, Application, User and RoleMapping, prefixed the new models with "My" and set up the relations entirely in MyRole using the code below (it's my MyRole.js)
/* Module dependencies*/var_=require('underscore');varutil=require('util')vardebug=require('debug')('myapp:models:MyRole');module.exports=function(MyRole){MyRole.on('dataAccessConfigured',function(MyRole){process.nextTick(function(){// retrieve app model registryvarmodels=MyRole.app.models;// get MyApplication and MyUservarMyRoleMapping=models.MyRoleMapping;varMyApplication=models.MyApplication;varMyUser=models.MyUser;//MyApplication.hasAndBelongsToMany(MyRole,{through: MyRoleMapping,polymorphic: 'principal'});MyUser.hasAndBelongsToMany(MyRole,{through: MyRoleMapping,polymorphic: 'principal'});// optional inverted relationsMyRole.hasMany(MyApplication,{through: MyRoleMapping,polymorphic: 'principal',invert: true});MyRole.hasMany(MyUser,{through: MyRoleMapping,polymorphic: 'principal',invert: true});});});};
By the way:
As you can see I still had the problem that was reported was by coodoo in #410 and by me in #425. The relations on the show up in explorer but not on the model when listening for 'dataAccessConfigured' (I guess that was the "new" event to listen to to be notified that all models are ready to go.). I solved that by using process.nextTick().
This could possibly be my problem for the current situation that it works on the model level but is not shown in the loopback-explorer.
I changed the listener to dataSourceAttached, but I still need the process.nextTick to access the methods. The code I wrote for the polymorphic relations does not work without the process.nextTick. Without it I get a TypeError: Cannot read property 'models' of undefined Error
Activity
raymondfeng commentedon Aug 4, 2014
I think we should try to leverage http://docs.strongloop.com/display/LB/Polymorphic+relations.
nvdnkpr commentedon Aug 4, 2014
I'm currently building my app with LB1 but I have an on LB2 with migration in my mind. I already read about the polymorphic relations, but their aren't used yet in the Role -> RoleMapping -> User/Application/Role Model. Any ETA ?
nvdnkpr commentedon Aug 6, 2014
If I extend Role and RoleMapping (I already have an extended User model) can I then already model it with the polymorphic relations ?
raymondfeng commentedon Aug 6, 2014
You should be able to override the relations. Can you give a try and let us know?
nvdnkpr commentedon Aug 6, 2014
It works... I managed to extend Application, User, Role and RoleMapping in the following way:
(Class with "My" prefix are the extension)
and it worked since I got the following methods on the following classes:
on
MyUser: __[findById, destroyById, ...]__roles, …on
MyApplication: __[findById, destroyById, ...]__roles, …on
MyRole: __[__findById, destroyById]__applications, …so it seem to work on the model level.
But they don't show up in the Explorer, although e.g.
MyApplication.sharedClass.find('__findById__roles', false).sharedistrue.I guess that comes from the fact that the classes' relations were added "after" they were published.
Is there a way to republish all published classes ?
raymondfeng commentedon Aug 6, 2014
Cool.
nvdnkpr commentedon Aug 6, 2014
I extended Role, Application, User and RoleMapping, prefixed the new models with "My" and set up the relations entirely in MyRole using the code below (it's my MyRole.js)
By the way:
As you can see I still had the problem that was reported was by coodoo in #410 and by me in #425. The relations on the show up in explorer but not on the model when listening for 'dataAccessConfigured' (I guess that was the "new" event to listen to to be notified that all models are ready to go.). I solved that by using process.nextTick().
This could possibly be my problem for the current situation that it works on the model level but is not shown in the loopback-explorer.
nvdnkpr commentedon Aug 6, 2014
Regarding 3.
How can I get that to work ? Your PR seemed to have failed, so what is the event to listen on with the loopback-explorer ?
raymondfeng commentedon Aug 6, 2014
You should listen dataSourceAttached which will be emitted after dataAccessConfigured.
nvdnkpr commentedon Aug 6, 2014
I changed the listener to dataSourceAttached, but I still need the process.nextTick to access the methods. The code I wrote for the polymorphic relations does not work without the
process.nextTick. Without it I get aTypeError: Cannot read property 'models' of undefinedErrornvdnkpr commentedon Aug 7, 2014
It seems the polymorphic relations arent that stable after all. I posted a new issue, see #446
nvdnkpr commentedon Aug 8, 2014
After #446 being closed, I managed (succesfully) to model the polymorphic relation (which btw still needed a
process.nextTickto work:Then I tried to model the same relationship via the JSON files using
and the appropriate relation modeling on MyRole:
but that created a wrong data model for MyRoleMapping (id, principalType, principalId, applicationId, userId, roleId).
Did I model it wrong or is this just another bug ? If so tell me, I'm going to open another issue ;)
superkhau commentedon Feb 26, 2015
@raymondfeng Is this still relevant?
mike-aungsan commentedon Nov 5, 2015
I still have similar issue extending RoleMapping, AccessToken and ACL
behrad commentedon Dec 14, 2015
#1879