fun_with_flags icon indicating copy to clipboard operation
fun_with_flags copied to clipboard

Add a custom query option to Ecto queries, closes #94

Open SteffenDE opened this issue 3 years ago • 2 comments

When having a setup similar to what's described in the official Ecto guides on setting up multi tenancy with foreign keys, the queries originating from FunWithFlags can fail, as the tenant key is not set. See https://hexdocs.pm/ecto/multi-tenancy-with-foreign-keys.html.

This PR adds a custom query option (:fun_with_flags) to allow an easy detection of these queries and to skip the tenant key check. The test repo was changed to check for this option and raise if it is not set.

Closes #94.

SteffenDE avatar Sep 15 '22 10:09 SteffenDE

Oh, I just saw that there already was a similar issue and PR. I'll check that and close this PR if necessary.

SteffenDE avatar Sep 15 '22 10:09 SteffenDE

I think this PR is fine and actually implements the solution that was agreed on in #94.

SteffenDE avatar Sep 15 '22 10:09 SteffenDE

For reference, I've tidied up the documentation to make it clearer how this works: https://github.com/tompave/fun_with_flags/commit/00cd00a6eeb746994649f2e828f93cbb7bd40470

I find the fact that prepare_query/3 only support the Query API a bit confusing, so I'd like to explain its gotchas.

tompave avatar Sep 25 '22 10:09 tompave

This has been released on Hex with version 1.10.0.

tompave avatar Oct 23 '22 21:10 tompave