jtwebman / bookshelf-scopes

Giving you Rails like scopes in Bookshelf.js.
MIT License
14 stars 3 forks source link

Fix unscoped when using postgres and raw queries #5

Open ariwbolton opened 4 years ago

ariwbolton commented 4 years ago

Should fix https://github.com/jtwebman/bookshelf-scopes/issues/4.

This change should be non-controversial: _.isMatch(object, source) is equivalent to _.matches(source)(object), but _.isMatch doesn't deep clone the source.

I've updated a test to "cover" this (in the hopes that perhaps eventually it'll be valuable), but unfortunately we'd need unit tests against postgres, too, instead of just sqlite, to confirm that this issue isn't occurring. Note that the test wouldn't fail if the issue exists, it would simply log an error and succeed anyways. (In the project I'm working on, this issue only seems to cause tests to fail when many concurrent connections are already open, and with many tests being run. I don't know what the exact problem is, but I'm not sure it's worth it to spend a bunch of time trying to design a more effective test; this should at least log an error when it's occurring)

That said, I've manually tested against another project which does use postgres, and it seems the issue has disappeared with this change (and generally that unscoping works as before).