Sails: Cannot use OR in populate subcriteria with one value null

Created on 5 Apr 2016  路  5Comments  路  Source: balderdashy/sails

Waterline version:0.21.1
Node version:5.0.0
NPM version: 3.5.2
Operating system: Windows 10


I need something like this

User.findOneByEmail(email) .populate('patients', { where: { disabled: [false,null] } })

but the populate cames empty in that case but if I do in this way:

User.findOneByEmail(email) .populate('patients', { where: { disabled: null } })

works fine

Most helpful comment

Hi @fatalhck! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

_If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]._

All 5 comments

Hi @fatalhck! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

_If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]._

ok, fixed!

Thanks @fatalhck I'll take a look. Also please don't pollute the comments with +1's.

Thanks

Ah @fatalhck I see the issue. IN queries get expanded to the following in SQL:

disabled=false or disabled=null

The disabled=null value is invalid SQL. In this case you want to use an OR query which should return the correct values.

User.findOne({ email: email })
.populate('patients', { 
  or: [
    { disabled: false },
    { disabled: null }
  ]
})
.exec(/* ... */);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mahfuzur picture mahfuzur  路  3Comments

Sytten picture Sytten  路  4Comments

3imed-jaberi picture 3imed-jaberi  路  3Comments

randallmeeker picture randallmeeker  路  4Comments

pawankorotane picture pawankorotane  路  3Comments