Skip to content

Doc: how to pass filter/where argument to find and findOne #47

Closed

Description

@pbrain19

SDK seems to forget to put the filter= before the where clause of any search. Also findOne expects array rather than object.

Activity

  1. bajtos commented on May 26, 2014

    @bajtos
    Member

    Hi @pbrain19, thank you for reporting this issue, we appreciate you are willing to invest your time to make LoopBack a better framework.

    Now I need more information to reproduce your problem, at least the angular code of your filter and findOne request(s).

    Possibly related: strongloop/loopback#279.

  2. bajtos commented on May 26, 2014

    @bajtos
    Member

    Moving here the conversation from strongloop/loopback-sdk-angular-cli#6.

    The sdk makes the request to

    GET /api/activities/findOne?where=%7B%22id%22:%225382552935ee740000609057%22%7D
    

    That URL suggests you are calling the API incorrectly.

    // incorrect
    User.findOne({ where: { id: '5382552935ee740000609057' } });
    // correct
    User.findOne({ filter: { where: { id: '5382552935ee740000609057' } } });

    I can see you were not able to read the generated API docs (strongloop/loopback-sdk-angular-cli#7). I am wondering: if our main documentation included samples how to query models via the generated API, would it help you to not run into this issue? (Have you read that doc page at all?)

  3. pbrain19 commented on May 26, 2014

    @pbrain19
    Author

    http://docs.strongloop.com/display/LB/Querying+models

    Please look at example... It does not say anything about adding filter inside query

  4. bajtos commented on May 26, 2014

    @bajtos
    Member

    http://docs.strongloop.com/display/LB/Querying+models

    Please look at example... It does not say anything about adding filter inside query

    Those examples are showing how to use the server-side (node.js) API.

    The SDK for AngularJS has a different API:
    http://docs.strongloop.com/display/DOC/AngularJS+JavaScript+SDK

    /cc @crandmck FYI. I am not sure if there is a reasonable way how to distinguish between client-side and server-side APIs in our docs.

  5. pbrain19 commented on May 26, 2014

    @pbrain19
    Author

    The angular doc should be enhanced a bit... Just a tiny bit to help beginners

  6. changed the title [-]Improper calls being made by sdk[/-] [+]Doc: how to pass filter/where argument to `find` and `findOne`[/+] on Jul 23, 2014
  7. raymondfeng commented on Sep 2, 2014

    @raymondfeng
    Member

    @crandmck Can you help enhance the docs?

  8. crandmck commented on Sep 3, 2014

    @crandmck
    Contributor

    OK, I think I see the issue here. Angular client must use the REST API for queries (vs. the Node API used on server). The REST API requires using the literal "filter" in the query string, but Node API does not. In this case, you are passing "stringified JSON", which I've been meaning to add to the docs for a while, anyway...

    I added the a description here: http://docs.strongloop.com/display/LB/Querying+models#Queryingmodels-UsingstringifiedJSONinRESTqueries. @raymondfeng Can you please confirm that I got it right?
    I also added links from each filter article, e.g. http://docs.strongloop.com/display/LB/Where+filter.

    Should I add a note somewhere in the Angular SDK docs? If so, where? I couldn't find an obvious place.

  9. bajtos commented on Sep 4, 2014

    @bajtos
    Member

    I added the a description here: http://docs.strongloop.com/display/LB/Querying+models#Queryingmodels-UsingstringifiedJSONinRESTqueries. @raymondfeng Can you please confirm that I got it right?

    I think your example is incorrect, this the query that works for me:

    GET /api/activities/findOne?filter={ where: { id: '53825529' } }
    

    However, it's entirely possible that both my and your versions are correct. I know the query string parser supports a lot of different flavours.

    Should I add a note somewhere in the Angular SDK docs? If so, where? I couldn't find an obvious place.

    I'd say this should be added to the auto-generated API docs. Which is not possible at the moment, because the filter argument is of a generic object type, thus the code generator has no way to tell that it is a special type.

  10. crandmck commented on Sep 10, 2014

    @crandmck
    Contributor

    OK, I made that correction and clarified the text a bit. I believe this can be closed.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions