Skip to content

Fails call $prototype$__get__snippeds() with TypeError: undefined is not a function #42

Closed

Description

@Rikhart

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):

TypeError: undefined is not a function
at http://localhost:3000/bower_components/angular-resource/angular-resource.js:582:27
at Array.forEach (native)

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.

Activity

  1. bajtos commented on Apr 28, 2014

    @bajtos
    Member

    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:

    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.

  2. bajtos commented on May 14, 2014

    @bajtos
    Member

    Bug triage: closing the issue due to no activity in the last 2 weeks.

  3. rolibb commented on Sep 24, 2014

    @rolibb

    thank you so much, i had the same problem but now i resolved with this information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions