-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lb-ng: Issue when working with related models #221
Comments
@markusiseli not sure if this is the fix, but you may need to explicitly allow methods for these related models in the user ACL (user.json). See https://docs.strongloop.com/display/public/LB/Accessing+related+models#Accessingrelatedmodels-Restrictingaccesstorelatedmodels example:
|
@dancingshell thanks for this, it pointed me to the solution. Here is an excerpt from my lb-services.js file with my comments:
Thus, for my current models, the fix was to expose the |
Hi @markusiseli, thanks for bringing this up, trying to understand the issue, so basically the bug is: this following line might provide some insight to whomever fixing issue:
|
@davidcheung yes. I used |
@markusiseli thanks! that would be great, |
@davidcheung please see following repository (did not succeed in generating gist): |
@davidcheung, threw a waiting label on here even though in this case we are waiting for you! 😉 @markusiseli, we generally prefer a repo over a gist! Makes our lives easier when digging for the root cause of an issue, thanks. |
Thanks @markusiseli! 😄 I probably won't be able to get to it today, but I think it should be enough for me to reproduce the issue |
Thanks @markusiseli, I can reproduce this problem, |
I have this problem as well without any acls setup |
I think this is the relevant code that's assuming a // sort the names to make sure the get method creating the scope
// is emitted first (R.categories before R.categories.create)
Object.keys(scopeMethods).sort().forEach(function(methodName) { The fix should be relatively straightforward - check whether Are there any volunteers for contributing this fix? I am happy to help you along the way, just mention my GH handle in the pull request description. |
Given two simple related models: user and answer, defined as follows:
user.json:
and answer.json:
The client-side code runs fine, does all the user authentication etc. but creating an answer instance, given the user model using
User.answers.create({"id": some_user_id}, {some_answer_json});
throws an Uncaught TypeError: Cannot set property 'create' of undefined.I tracked the error back to lb-ng: lb-ng creates the following code (lb-services.js) for creation of an answer instance, given the user (R in this case is the user resource):
The issue with this code is that the property
answers
of R - as inR.answers
- was not defined before definingR.answers.create
, hence the error. This error occurs with all similar methods on related models, where the relation name is inserted: e.g.R.answers.createMany
, etc.Here is my very temporary fix:
In lb-services.js, manually initialize
R.answers = {};
before the lineR.anwers.create = function() {
works and the answer instance gets created with the creatorId in the DB.If this is a bug, I'd be glad to help fix it, but would need instructions. If this is not a bug, please let me know what is wrong with my understanding.
The text was updated successfully, but these errors were encountered: