Skip to content

Rest filter problems with undefined model entries. #1573

Closed

Description

@cleaner321

I'm working on a project and try to write a search mask for emails.
I was a little confused while I was testing it, because of the output from the rest filter option:

That's right:
/api/companies?where[or][0][mail][like]=a --> returns all items with a 'a' in it

That's acceptable:
/api/companies?where[or][0][mail][like]=undefined --> returnes all, items without a defined mail

Confused by this:
/api/companies?where[or][0][mail][like]=u --> returnes all, items without a defined mail
/api/companies?where[or][0][mail][like]=.de --> returnes all, items without a defined mail

Can you help me please to make it possible to search for email endings (.de)

Activity

  1. changed the title [-]Rest filter problems with undefined model entries.[/-] [+]Rest filter problems with undefined model entries. bug[/+] on Aug 7, 2015
  2. changed the title [-]Rest filter problems with undefined model entries. bug[/-] [+]Rest filter problems with undefined model entries.[/+] on Aug 7, 2015
  3. raymondfeng commented on Aug 7, 2015

    @raymondfeng
    Member

    You should use the following convention:

    http://localhost:3000/api/notes?filter[where][or][0][mail][like]=.de

    A less confusing way (using stringfied json) is:

    http://localhost:3000/api/notes?filter={"where":{"or":[{"mail":{"like":".de"}}]}}

    BTW, you don't need to use "or" in this case.

  4. cleaner321 commented on Aug 7, 2015

    @cleaner321
    Author

    Thank's for your quick reply.
    I took the where without the filter[] because this didn't work in companies/count? ...

    I changed the code to match exactly your convention and the problem still exists. It still doesn't work.

    BTW, this is my full request:
    http://localhost:3000/api/companies
    ?filter[where][and][0][team]=1
    &filter[where][or][1][name][like]=.de
    &filter[where][or][2][mail][like]=.de
    &filter[order]=nameDESC
    &filter[limit]=10
    &filter[skip]=0

    I think the problem is: If text is missing it is declared as "undefined" and because of that the filter will return all undefined fields when I search for a subset of the word undefined.

  5. raymondfeng commented on Aug 7, 2015

    @raymondfeng
    Member
    1. Please note that count() takes the where argument instead of filter.
    2. Here is the query in JSON format (after adding a space for order):
    { filter: 
       { where: 
          { and: [ { team: '1' } ],
            or: [ { name: { like: '.de' } }, { mail: { like: '.de' } } ] },
         order: 'name DESC',
         limit: '10' } }

    Do you want to find companies with team === '1' && (name like '.de' || mail like '.de')?

  6. cleaner321 commented on Aug 7, 2015

    @cleaner321
    Author

    Yes I'm searching for this:
    team === '1' && (name like '.de' || mail like '.de')

    I try to make an example:
    If I type in my search mask the letters "de" I want to get results where "de" is find in

    1. The name and
    2. The mailadress.

    My Problem: If I type in "de" it shows me names and emailadresses with this letters in it but it also shows me e.g. id 1 (see below) because there is no email adress (the adress is undefined). Because of undefined I get this wrong result [1,2,3] instead of the right result [2,3].
    I try to get this:
    team === '1' && ((name like '.de' && name nlike undefined) || (mail like '.de'&& mail nlike undefined))

    Example entries:
    {
    "id": "1",
    "name": "Raymond Feng",
    "createdAt": "2015-08-07T18:55:22.556Z",
    "updatedAt": "2015-08-07T18:55:22.556Z"
    },
    {
    "id": "2",
    "name": "cleaner321",
    "email": "foo@bar.de",
    "createdAt": "2015-08-07T18:56:18.719Z",
    "updatedAt": "2015-08-07T18:56:18.719Z"
    },
    {
    "id": "3",
    "name": "Dennis",
    "email": "foo@bar.com",
    "createdAt": "2015-08-07T18:56:18.719Z",
    "updatedAt": "2015-08-07T18:56:18.719Z"
    }

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