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
Fails call $prototype$__get__snippeds() with TypeError: undefined is not a function #42
I am playing with loopback an on the back-end I have defined a relationship of:
User has many snippeds the problem at the moment is to get the snippeds from the client, this is my scenario:
First get the current user with : User.getCurrent(function (user) {
//Now when i trying get the snnippes from the user:
user.$prototype$__get__snippeds()
})
That make the request to the server: http://localhost:3000/api/users/535a05e2feca896653e30171/snippeds
responding with an array of objects I see that on a network of Javascript Debugger(Chrome) but show me also an error on a cosole(Chrome):
Apparently this error will be relationed with angular-resource library but I have changed many times my version of angular-resource and the error continue there.
How can I solve this problem ??. Thanks by yours answers.
First of all, you should not call __get__snippeds on a resource instance, but on the resource prototype:
User.prototype$__get_snippeds({id: user.id});
When you call the method on an instance, ngResource updates the instance with the data returned from the server, instead of creating a new resource. My guess is that ngResource is trying to work with the user object as if it was an array and fails with the TypeError when an array function is not found (e.g. user.push(item)).
Now even when you apply the change above, it still won't work for you, since the result will contain a list of users instead of a list of snippeds - see #26 for detailed explanation.
What version of loopback and loopback-angular are you using? loopback-angular v1.1.0 contains #29, which fixed #26. With this new version, you can write the following code to get a list of related Snipped models:
User.snippeds({id: user.id})
Note you have to upgrade loopback to v1.7.4 and loopback-datasource-juggler to v1.3.9 too.
Activity
bajtos commentedon Apr 28, 2014
Hi @Rikhart,
Thank you for reporting the issue.
First of all, you should not call __get__snippeds on a resource instance, but on the resource prototype:
When you call the method on an instance, ngResource updates the instance with the data returned from the server, instead of creating a new resource. My guess is that ngResource is trying to work with the
userobject as if it was an array and fails with the TypeError when an array function is not found (e.g.user.push(item)).Now even when you apply the change above, it still won't work for you, since the result will contain a list of users instead of a list of snippeds - see #26 for detailed explanation.
What version of loopback and loopback-angular are you using? loopback-angular v1.1.0 contains #29, which fixed #26. With this new version, you can write the following code to get a list of related Snipped models:
Note you have to upgrade loopback to v1.7.4 and loopback-datasource-juggler to v1.3.9 too.
bajtos commentedon May 14, 2014
Bug triage: closing the issue due to no activity in the last 2 weeks.
rolibb commentedon Sep 24, 2014
thank you so much, i had the same problem but now i resolved with this information.