tompave / fun_with_flags

Feature Flags/Toggles for Elixir
https://hexdocs.pm/fun_with_flags/FunWithFlags.html
MIT License
1.08k stars 79 forks source link

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

Closed SteffenDE closed 2 years ago

SteffenDE commented 2 years ago

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 commented 2 years ago

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

SteffenDE commented 2 years ago

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

tompave commented 2 years ago

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 commented 2 years ago

This has been released on Hex with version 1.10.0.