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
Are foreign keys supposed to populate automatically? #459
I am using mongodb, and I have a TestUsers has many Messages relatinship. I am have my access token set after logging in. I am making a POST to /messages, but it does not populate the foreign key automatically. Also, when I try to use my users id to access the messages, it gives me a 401. Did I setup my ACL and relationships properly?
I'm not exactly sure what you are doing. If you are doing a POST to /api/messages the foreign key will not be populated. If you post to /api/testusers/$someUserId/messages the key should be added for you.
The Role.OWNER dynamic role only checks for the following properties:
userId
owner
If you modify your relation to use that as a foreign key the 401 should go away.
Hopefully that helps. If this is not helpful, could you post a code example outlining what you are doing?
@ritch Thank you! I made the change and added userId as my foreign key, but is owner supposed to be a boolean, string, or id? Do I just put that as a property on my belongsTo object?
If you changed it to userId you should be good. It checks for either someModel.userId === currentUserId or someModel.owner === currentUserId. It is not a boolean.
I did a quick trace, and I dont understand why is my model being denied. I tried adding access to all in messages, but still don't really understand why.
@ritch I dug through the documentation, but I cant seem to get it right still. I am logging in to TestUser, then setting the access token and filling in the text field for userId, and making a GET request to /TestUsers/{userId}/messages and it still gives me a 401. This seems pretty straight forward, but it's not working for me; I am really lost. What might I be doing incorrectly? This is what I have right now:
Activity
ritch commentedon Aug 11, 2014
I'm not exactly sure what you are doing. If you are doing a
POSTto/api/messagesthe foreign key will not be populated. If you post to/api/testusers/$someUserId/messagesthe key should be added for you.The
Role.OWNERdynamic role only checks for the following properties:userIdownerIf you modify your relation to use that as a foreign key the
401should go away.Hopefully that helps. If this is not helpful, could you post a code example outlining what you are doing?
dagumak commentedon Aug 11, 2014
@ritch Thank you! I made the change and added userId as my foreign key, but is owner supposed to be a boolean, string, or id? Do I just put that as a property on my belongsTo object?
ritch commentedon Aug 11, 2014
If you changed it to
userIdyou should be good. It checks for eithersomeModel.userId === currentUserIdorsomeModel.owner === currentUserId. It is not a boolean.ritch commentedon Aug 11, 2014
Here is a link to the actual implementation:
https://github.com/strongloop/loopback/blob/master/lib/models/role.js#L250
dagumak commentedon Aug 12, 2014
I did a quick trace, and I dont understand why is my model being denied. I tried adding access to all in messages, but still don't really understand why.
dagumak commentedon Aug 19, 2014
@ritch I dug through the documentation, but I cant seem to get it right still. I am logging in to TestUser, then setting the access token and filling in the text field for userId, and making a GET request to
/TestUsers/{userId}/messagesand it still gives me a 401. This seems pretty straight forward, but it's not working for me; I am really lost. What might I be doing incorrectly? This is what I have right now:raymondfeng commentedon Aug 19, 2014
Please add the following ACL entry to your TestUser model:
{ "principalType": "ROLE", "principalId": "$owner", "permission": "ALLOW", "property": "__get_messages" }raymondfeng commentedon Aug 19, 2014
See https://groups.google.com/forum/#!searchin/loopbackjs/acl$20relation/loopbackjs/c48UGMHaNDg/nAplfywzKXYJ
dagumak commentedon Aug 23, 2014
@raymondfeng That worked! Thanks! @fabien Thanks for your help!