Skip to content

'Find Where' in ModelRepository #74

Open

Description

@Rajan

I'm able to use FindAll but how do I get all values for a particular users for a feature like favorites?

Activity

  1. changed the title [-]'Find Where' in ModelRepository Model.[/-] [+]'Find Where' in ModelRepository[/+] on May 18, 2015
  2. philippdhh commented on May 26, 2015

    @philippdhh

    Hello,

    I think I am struggling with the same problem.

    I successfully followed the Android SDK documentation and managed to connect a ListView to a loopback API. Actually I can show all elements of one rest ressource in a list now.

    The Android SDK calls the API provided by loopback framework with the URL http://api.wdapp.de/api/bets

    This delivers all "bets" to the client.

    As the amount of elements will increase and only current "bet" objects will be relevant I need to filter the bets on the server rather than doing this on the client after fetching all of them.

    Loopback offers the filters for this. I would like to call:
    http://api.wdapp.de/api/bets?filter[where][dueDate][gte]=2015-05-27&filter[order]=dueDate%20ASC
    for example to only show current objects in my prefered order.

    Actually I hoped to find a findByWhere or findByCriteria method in the API to solve this problem.

    When I think about using a Doctrine ORM Repository (PHP) there is a solution like this:

        $criteria = new Criteria();
        $criteria->where($criteria->expr()->gt('dueDate',new \DateTime))
            ->orderBy(array("dueDate" => Criteria::ASC));
        $bets = $this->getDoctrine()->getRepository('Bet')->matching($criteria);
    

    Is there any best practice to solve this problem using Loopback Android SDK?

    Thank you in advance,
    Philipp

  3. bajtos commented on Jun 2, 2015

    @bajtos
    Contributor

    Oh, this is an unintended omission. The class ModelRepository should implement a find method that would accept the filter object (a hash map) as an argument.

  4. bajtos commented on Jun 2, 2015

    @bajtos
    Contributor

    The hash-map based version is a minimum implementation. A better solution is to provide a criteria builder similar to what is described in #74 (comment).

    I am afraid this issue is not a high priority for us at the moment. However, if there is any volunteer willing to contribute this feature, then I am more than happy to help him along the way.

  5. serjooo commented on Apr 9, 2017

    @serjooo

    For anyone trying to make where work you only have to do the following:

    HashMap<String, Object> filter = new HashMap<>();
    HashMap<String, Object> whereMap = new HashMap<>();
    HashMap<String, Object> params = new HashMap<>();
    params.put("filter_field", field_value);
    whereMap.put("where", params);
    filter.put("filter", whereMap);
    invokeStaticMethod("staticMethod", filter, new JsonObjectParser(this, callback) {
            });
    

    Also remember in my example I have used JsonObjectParser for returning a signle object. If they were multiple objects use the JsonArrayParser

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions