Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql filter where on relation #2834

Closed
dahuahe opened this issue Oct 6, 2016 · 2 comments
Closed

mysql filter where on relation #2834

dahuahe opened this issue Oct 6, 2016 · 2 comments
Labels

Comments

@dahuahe
Copy link

dahuahe commented Oct 6, 2016

In model A

{ "name": "A",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "AreaCode": {
      "type": "string",
      "default": ""
  }
  },
  "relations": {
    "B": {
      "type": "hasOne",
      "model": "B",
      "foreignKey": ""
    }
  }
}

In model B

{
  "name": "B",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "Name": {
      "type": "string",
      "default": ""
    }
  },
  "relations": {
    "A": {
      "type": "belongsTo",
      "model": "A",
      "foreignKey": ""
    }
  }
}

if I find A with B like this /api/A {filter:{include:"B"}}} I will get this data

[{
id:1
AreaCode:"test1",
B:{Name:"xxxxx"}             // (if A id 1 hasOne B)
}.{
id:2
AreaCode:"test2",         //   (A id 2 don't haveOne B)
}......]

But I want to get this data

[{
id:1
AreaCode:"test1",
B:{Name:"xxxxx"}             // (if A id 1 hasOne B) only get data A has B  
},{                                         
id:3
AreaCode:"test1",
B:{Name:"XXXX"}
}......(A hasOne B's data)]

so I try find A with B like this /api/A
{filter:{include:"B",where:{B:{neq:''}}}}}} or
{filter:{include:"B",where:{neq:{B:''}}}}}}
it's doesn't work!!
How i to write filter ??or to do??

@0candy
Copy link
Contributor

0candy commented Oct 6, 2016

@dahuahe When you apply filters to related models, the query returns results from the first model plus any results from related models with the filter query, similar to a "left join" in SQL.
See https://docs.strongloop.com/display/APIC/Include+filter#Includefilter-Includewithfilters

@0candy 0candy closed this as completed Oct 6, 2016
@0candy 0candy reopened this Oct 6, 2016
@0candy
Copy link
Contributor

0candy commented Oct 6, 2016

See feature request #683.
Closing this issue as a dup.

@0candy 0candy closed this as completed Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants